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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:45:06  来源:igfitidea点击:

To Add Minimize /Maximize button to JDialog orJPanel

javaswingjpaneljdialog

提问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.setUndecoratedand add required Windows decoration back, notice resources for JDialog/JWindow came from Native OS, valid for SystemLookAndFeelonly and could be CrossPlatform 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 JOptionPaneand with modified contents, there you can put any JComponentsand/with returns value too
  • 是的,但是您可以使用JOptionPane和修改内容,在那里您也可以放置任何JComponents和/带有返回值

回答by Mordechai

JDialog: No.

JDialog: 不。

JPanel: Yes, simply use JButtonssetting the JFrame#setMaximizedStatevalue, in the listeners, but not on JDialog.

JPanel: 是的,只需在侦听器中使用JButtons设置JFrame#setMaximizedState值,而不是在JDialog.