设置 JDialog 的最大大小?

编程入门 行业动态 更新时间:2024-10-28 22:25:52
本文介绍了设置 JDialog 的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

简短版本:我需要做一些棘手的事情才能让 JDialog 的 setMaximumSize() 工作吗?

The short version: do I need to do something tricky to get JDialog's setMaximumSize() to work?

完整版:我有一个 JDialog(布局管理器:BorderLayout),它包含一个滚动窗格和一个底部带有提交按钮的 JPanel.

The full version: I've got a JDialog (layout manager: BorderLayout) which contains a scroll pane and a JPanel on the bottom with the commit buttons.

滚动窗格包含一个 JPanel,它是在系统的其他地方动态构建的.

The scroll pane contains a JPanel which is built dynamically elsewhere in the system.

我想要的是让对话框围绕 JPanel 动态调整自身大小,直到达到特定大小,然后开始增长滚动条.这或多或少是默认情况下发生的情况,除了最大尺寸似乎是我的显示器的尺寸.

What I want is for the dialog to dynamically size itself around the JPanel up to a certain size, and then start growing scrollbars. This is, more or less, what happens by default, except the maximum size seems to be the size of my monitor.

我认为这就是继承自 java.awt.Component 的 .setMaximumSize() 方法所做的,但设置它似乎没有任何效果.

I thought this is what the .setMaximumSize() method inherited from java.awt.Component did, but setting it doesn't seem to have any effect.

设置首选大小确实有影响 - 但无论如何,对话框总是那个大小,这真的不是我想要的.

Setting the preferred size does has an effect - but then the dialog is always that size no matter what, which really isn't what I want.

(如果我在滚动窗格上设置最大/首选大小属性,效果是一样的.)

(And the effects are the same if I set the maximum/preferred size properties on the scroll pane.)

我是否遗漏了一些非常明显的内容?是否有一些我不知道的古怪 JDialog/BorderLayout/MaximumSize 交互?

Have I missed something tremendously obvious? Is there some wacky JDialog / BorderLayout / MaximumSize interaction I don't know about?

推荐答案

使面板实现可滚动是 的方法.另请参阅(除了 Trashgod 已提供的教程链接)Rob 的博客条目

Make the panel imlement Scrollable is the way to go. See also (in addition to the tutorial link Trashgod already provided) Rob's blog entry

tips4java.wordpress/2009/12/20/scrollable-panel/

然后:

1) 以对典型内容合理的方式实现 getPreferredScrollableViewportSize()(对于 JList,这是要显示的首选行数,又名:visibleRowCount)2)为那些合理的条款"实施setter/getter

1) implement getPreferredScrollableViewportSize() in terms reasonable for the typical content (for a JList f.i. that's the preferred number of rows to show, aka: visibleRowCount) 2) implement setters/getters for those "reasonable terms"

该附加层(协调合理条款")允许所有协作组件尽最大努力提出稳健的大小提示,而不会产生不友好的干扰,如 setXXSize(这是一个no-no-never-ever,只是忘记那些方法存在;)

That additional layer (coordiates "reasonable terms") allows all collaborating components to do their best to come up with robust size hints without unfriendly interference as setXXSize (which is a no-no-never-ever, simply forget those methods exist ;)

更多推荐

设置 JDialog 的最大大小?

本文发布于:2023-06-05 11:33:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/518789.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小   JDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!