setSize() 不适用于 JFrame

2022-01-24 00:00:00 java swing jframe
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

class Demo
{
    JFrame jf;
    Demo()
    {
        jf=new JFrame("Demo");
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(5000,5000);
        jf.setVisible(true);
        System.out.println(jf.getSize());
    }
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {

            @Override
            public void run()
            {
                new Demo();
            }
        });
    }
}

我对 JFrame 使用 jf.setSize(5000, 5000) 但之后 getSize 返回其他大小:java.awt.Dimension[width=1386,height=788](我的屏幕分辨率是 1366x768)我可以将帧大小设置为大于屏幕大小吗?可能这种行为是由一些框架属性提供的,但我不知道它们.

I use jf.setSize(5000, 5000) for JFrame but after that getSize returns other size: java.awt.Dimension[width=1386,height=788] (my screen resolution is 1366x768) Can I set frame size greater than screen size? probably such behaviour is provided with some frame properties but I don't know about them.

推荐答案

尝试使用 setPreferredSize 而不是 setSize.适用于我的情况(Ubuntu 12.04+GNOME 3).

Try using setPreferredSize instead of setSize. Works in my case (Ubuntu 12.04+GNOME 3).

相关文章