Frage

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

setExtendedState( getExtendedState() | JFrame.MAXIMIZED_BOTH);
War es hilfreich?

Lösung 2

After frame.setVisible(true):

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top