设置 JDialog 的最大大小? [英] Setting the maximum size of a JDialog?

查看:30
本文介绍了设置 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

http://tips4java.wordpress.com/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 的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆