Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Get JFrame window size information in Java
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
