Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
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.