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

查看:137
本文介绍了设置JDialog的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

完整版:我有一个JDialog(布局) manager: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.

想到这个是.setMaximumSize()方法从java.awt.Component继承的是什么,但设置它似乎没有任何影响。

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?

推荐答案

使面板imlement Scrollable是 的方式去。另请参阅(除了已提供的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 fi,又名:visibleRowCount)

2)为那些合理条款实施setter / getters

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(这是一个不 - 不 - 永远不会,只是忘记存在这些方法;)

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天全站免登陆