I set maximized frame: setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
Now how I can get this size, because when I call getSize()
or getPreferredSize
it returns 0 0
?
You will get the maximized size correctly after the setVisible(true);
is executed.
public NewJFrame() { // Constructor
initComponents();
this.setExtendedState( getExtendedState() | JFrame.MAXIMIZED_VERT | Frame.MAXIMIZED_HORIZ);
// height and width still prints the original values
System.out.println(this.getSize().height + " " + this.getSize().width);
}
....
public static void main(String args[]) { // main
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
NewJFrame foo = new NewJFrame();
foo.setVisible(true);
// after setVisible(true) actual maximized values
System.out.println(foo.getSize().height + " " + foo.getSize().width);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With