java 将最小化/最大化按钮添加到 JDialog 或 JPanel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13718054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
To Add Minimize /Maximize button to JDialog orJPanel
提问by Nidhi
Is it possible to add maximize/minimize button to the JDialog? if not then can we add these buttons to JPanel?
是否可以向 JDialog 添加最大化/最小化按钮?如果没有,那么我们可以将这些按钮添加到 JPanel 吗?
I have a JPanel and inside that panel there is a JDialog.I want to add a minimize/maximize button such that when that button is clicked JDialog and the components under JDialog get adjusted according to the JPanel. like when i click maximize then jpanel should get enlarged and components inside that panel(JDialog) also get enlarged and vice versa for minimize button. The solution I got from here is for JPanel inside a JFrame. But my JPanel is standalone only.
我有一个 JPanel,在该面板内有一个 JDialog。我想添加一个最小化/最大化按钮,以便在单击该按钮时 JDialog 和 JDialog 下的组件根据 JPanel 进行调整。就像当我点击最大化然后 jpanel 应该被放大并且该面板(JDialog)内的组件也会被放大,反之亦然对于最小化按钮。我从这里得到的解决方案是针对 JFrame 中的 JPanel。但我的 JPanel 只是独立的。
采纳答案by mKorbel
Is it possible to add maximize/minimize button to the JDialog?
是否可以向 JDialog 添加最大化/最小化按钮?
- not, don't do that, (even there are a few dirty hacks) you can to
JDialog.setUndecorated
and add required Windows decoration back, notice resources for JDialog/JWindow came from Native OS, valid forSystemLookAndFeel
only and could beCrossPlatfor
m sensitive
- 不,不要这样做,(即使有一些肮脏的黑客)您可以
JDialog.setUndecorated
添加所需的 Windows 装饰,注意 JDialog/JWindow 的资源来自本机操作系统,仅对SystemLookAndFeel
并且可能是CrossPlatfor
敏感的
if not then can we add these buttons to JPanel?
如果没有,那么我们可以将这些按钮添加到 JPanel 吗?
- yes, but you can to use
JOptionPane
and with modified contents, there you can put anyJComponents
and/with returns value too
- 是的,但是您可以使用
JOptionPane
和修改内容,在那里您也可以放置任何JComponents
和/带有返回值
回答by Mordechai
JDialog
: No.
JDialog
: 不。
JPanel
: Yes, simply use JButtons
setting the JFrame#setMaximizedState
value, in the listeners, but not on JDialog
.
JPanel
: 是的,只需在侦听器中使用JButtons
设置JFrame#setMaximizedState
值,而不是在JDialog
.