栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

需要无效的Swing组件的高度

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

需要无效的Swing组件的高度

花了一段时间(可能是因为这里很早:-)来理解问题,所以只是确保我明白了:

  • 底部组件的大小可以是用户始终决定的大小
  • 调整框架大小时,顶部组件应发生所有高度变化
  • 有一个还原为默认大小的选项,与之前的任何设置无关
  • “默认”表示底部组件的固定高度必须为xx

如果这样,解决方案是将框架调整大小与底部组件的大小分开。第二个选择是无效的:调整框架大小并将底部comp调整大小包装到invokeLater中(EventQueue或SwingUtilities,无关紧要)。

void restoreDefaults() {    f.setSize(f.getWidth(), getDesktopRect(f.getGraphicsConfiguration()).height);    SwingUtilities.invokeLater(new Runnable() {        public void run() { sp.setDividerLocation(sp.getSize().height - 100);        }    });}

这样可以保证按预期工作,因为invokeLater在所有已排队的事件之后将请求放到最后:

 /** * Causes <i>doRun.run()</i> to be executed asynchronously on the * AWT event dispatching thread.  This will happen after all * pending AWT events have been processed.  [...] * If invokeLater is called from the event dispatching thread -- * for example, from a JButton's ActionListener -- the <i>doRun.run()</i> will * still be deferred until all pending events have been processed.


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454728.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号