To Add Minimize /Maximize button to JDialog orJPanel

只谈情不闲聊 提交于 2019-11-28 08:07:30

问题


Is it possible to add maximize/minimize button to the JDialog? if not then can we add these buttons to 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.


回答1:


Is it possible to add maximize/minimize button to the 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 for SystemLookAndFeel only and could be CrossPlatform sensitive

if not then can we add these buttons to JPanel?

  • yes, but you can to use JOptionPane and with modified contents, there you can put any JComponents and/with returns value too



回答2:


JDialog: No.

JPanel: Yes, simply use JButtons setting the JFrame#setMaximizedState value, in the listeners, but not on JDialog.



来源:https://stackoverflow.com/questions/13718054/to-add-minimize-maximize-button-to-jdialog-orjpanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!