How do Jpanel in JFrame automatically occupy all space available in JFrame in Java?
-
Trying to create the simplest app. But when the component is added
JPanel
TotalJFrame
♪JPanel
doesn't take all the space allowed. The results of the programme are as follows:"java.awt.Dimension[width=0,height=0]"
i.e. dimensionsJPanel
zero. How to do thatJpanel
placed inJFrame
, automatically occupied everything availableJFrame
spaceJava
? And could you get that dimension straight?Programme record:
public class Test1 extends JFrame{ Test1() { super("Графическое приложение"); setBounds(50,50,1000, 450); JPanel panel = new JPanel(); this.add(panel); System.out.println(this.getComponent(0).getSize()); }
public static void main(String[] args) throws IOException { new Test1(); }
}
-
You're right in the commentary. https://ru.stackoverflow.com/users/190934/zrrr You try to run the following code:
public class Test1 extends JFrame{ Test1 () { super("Графическое приложение"); setBounds(50,50,1000, 450); JPanel panel = new JPanel(); panel.setBackground(Color.BLUE); this.setContentPane(panel); }
public static void main(String[] args){ Test1 test = new Test1(); test.setVisible(true); System.out.println(test.getContentPane().getSize()); } }