Warning: file_put_contents(): Only 0 of 31158 bytes written, possibly out of free disk space in /var/www/html/cach3.com/read_page.php on line 150
Get JFrame window size information in Java
Tutorialspoint

1 Answer
Samual Sam

To get JFrame window size information, you can use the following −

environment.getMaximumWindowBounds();

For Screen Size −

config.getBounds()

For Frame Size −

frame.getSize());

The following is an example to get JFrame window size information −

Example

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
public class SwingDemo {
   public static void main(String[] args) {
      GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
      Rectangle bounds = environment.getMaximumWindowBounds();
      System.out.println("Screen Bounds = " + bounds);
      GraphicsDevice device = environment.getDefaultScreenDevice();
      GraphicsConfiguration config = device.getDefaultConfiguration();
      System.out.println("Screen Size = " + config.getBounds());
      JFrame frame = new JFrame("Frame Info");
      frame.setSize(500, 300); frame.setVisible(true);
      System.out.println("Frame Size = " + frame.getSize());
   }
}

Output

Screen Bounds = java.awt.Rectangle[x=0,y=0,width=1366,height=728]
Screen Size = java.awt.Rectangle[x=0,y=0,width=1366,height=768]
Frame Size = java.awt.Dimension[width=500,height=300]

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.