我设置了最大化的框架: setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
现在我怎么能得到这个尺寸,因为当我打电话getSize()
或getPreferredSize
它返回时0 0
?
setVisible(true);
执行后,您将正确获得最大化的大小.
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6472 次 |
最近记录: |