JFrame resizable height ONLY(JFrame 仅可调整高度)
问题描述
JFrame.setResizable(true) 允许用户调整窗口的宽度和高度.是否存在允许用户仅调整高度大小的方法?
JFrame.setResizable(true) lets the user resize both the width and height of a window. Does a method exist which allows the user to ONLY resize the height?
谢谢.
以下解决方案似乎不起作用.在 360x600 JFrame 上,
The solutions below do NOT seem to work. On a 360x600 JFrame,
setResizable(true);
pack();
setMaximizedBounds(new java.awt.Rectangle(0, 0, 360, 1200));
setMaximumSize(new java.awt.Dimension(360, 1200));
setMinimumSize(new java.awt.Dimension(360, 600));
setPreferredSize(new java.awt.Dimension(360, 600));
setVisible(true);
仍然允许完全拉伸 JFrame 的宽度,并且设置 setResizable(false) 不允许拉伸任何内容.
Still allows fully stretching the width of the JFrame, and setting setResizable(false) allows nothing to be stretched.
推荐答案
下面的代码做的很好.
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setSize(new Dimension(preferredWidth, getHeight()));
super.componentResized(e);
}
});
这篇关于JFrame 仅可调整高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JFrame 仅可调整高度
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
