Get size of componets in JFrame with full screen
Hi Guys,
I need to get componets(JPanel, JSplitPane, etc) size in main JFrame.
First the main frame default restore size is set by
"mainFrame.setSize(100,100);"
And then it is full-screened by
"mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);"
And when I get the size of jpanel inside the main frame,
the size is coming as default restore frame not full screen frame.
My purpose is to get the size when the frame is full size when the frame is opening(initiating).
You may understand if see the below code.
Thank you in advance.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GetComponentSizeimplements ActionListener
{
JFrame mainFrame;
JPanel subPanel;
JButton bt;
public GetComponentSize()
{
mainFrame =new JFrame();
subPanel =new JPanel();
bt =new JButton("Get Panel Size");
bt.addActionListener(this);
subPanel.add(bt);
mainFrame.getContentPane().setLayout(new BorderLayout());
mainFrame.getContentPane().add(subPanel, BorderLayout.CENTER);
mainFrame.setSize(100,100);//Default Restore size
mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);//Make frame full screen
mainFrame.setVisible(true);
System.out.println("First size:"+subPanel.getSize());//Print component JPanel size
}
publicvoid actionPerformed(ActionEvent e)
{
System.out.println("Second size:"+subPanel.getSize());
}
publicstaticvoid main(String arg[])
{
new GetComponentSize();
}
};

