setSize() doesn#39;t work for JFrame(setSize() 不适用于 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).
这篇关于setSize() 不适用于 JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:setSize() 不适用于 JFrame
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
