Java JFrame根据屏幕分辨率调整大小 [英] Java JFrame Size according to screen resolution

查看:1211
本文介绍了Java JFrame根据屏幕分辨率调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用myEclipse Matisse创建了java GUI。当我的屏幕分辨率是1024x768时,它工作正常,但当我更改分辨率时,我的GUI工作不正常。我希望我的GUI窗口应根据屏幕分辨率重新调整大小
我正在扩展JFrame来创建主窗口。

I created java GUI using myEclipse Matisse. when my Screen Resolution is 1024x768 it works fine but when i change resolution my GUI is not working fine. I want my GUI window should be re-sized according to the screen Resolution I am extending JFrame to create the main window.

 public class MyClass extends JFrame {

      //I am putting some controls here.

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      setBounds(0,0,screenSize.width, screenSize.height);
      setVisible(true);

      pack()

    }

this无法正常工作,我做什么,设置大小硬编码或使用ToolKit,帧大小保持不变。

this is not working, what ever i do, setting size hardcoded or by ToolKit using, the Frame Size Remains same.

推荐答案

你是调用 pack()会改变帧大小,使其适合内部组件。这就是我认为它缩小的原因。删除 pack()行,它应该可以工作。

You are calling pack() which changes the frame size so it just fits the components inside. That's why it is shrinking back I think. Remove the pack() line and it should work.

这篇关于Java JFrame根据屏幕分辨率调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆