在Java中获取JFrame窗口大小信息
要获取JFrame窗口大小信息,可以使用以下命令-
environment.getMaximumWindowBounds();
对于屏幕尺寸-
config.getBounds()
对于框架尺寸-
frame.getSize());
以下是获取JFrame窗口大小信息的示例-
示例
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());
}
}
输出结果
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]
以上是 在Java中获取JFrame窗口大小信息 的全部内容, 来源链接: utcz.com/z/316522.html