How can I get the width and height of an extended JFrame? (done through)

setExtendedState( getExtendedState() | JFrame.MAXIMIZED_BOTH);
有帮助吗?

解决方案 2

After frame.setVisible(true):

double width = frame.getSize().getWidth();
double height = frame.getSize().getHeight();

其他提示

Adding to my comment:

uhm whats wrong with calling getWidth and getHeight after setting JFrame to JFrame.MAXIMIZED_BOTH

are you sure you call it after JFrame is visible and size state has been changed? i.e:

frame.setExtendedState( getExtendedState() | JFrame.MAXIMIZED_BOTH);
frame.pack();
frame.setVisible(true);

System.out.println(frame.getWidth()+" "+frame.getHeight());

Another solution is simply get the screens size via

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
System.out.println("Screen Bounds: " + bounds ); 

as that would be the size of JFrame in JFrame.MAXIMIZED_BOTH state

frame.getContentPane().getSize();

You will lose the decoration title bar size. Or get the rootPane, even better.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top