简体   繁体   English

Java - Swing - JOptionPane填充

[英]Java - Swing - JOptionPane padding

From my main form I want to display a new form. 从我的主要表单我想显示一个新表单。

When the new form is opened, it needs to be treated as a child in that clicking on the parent brings forward the child for focus. 打开新表单时,需要将其视为子项,因为单击父项会将子项提前焦点。 JFrames aren't modal apparently, so I'm using: JFrames显然不是模态的,所以我使用:

JOptionPane.showOptionDialog(null, MYPANEL, "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null);

...Where MYPANEL looks identical to what I need in my form. ...... MYPANEL在我的表格中看起来与我需要的相同。

This works 100% as intended EXCEPT that there is padding (about 20px or so) between the panel edges and the JOptionPane dialog frame. 除了在面板边缘和JOptionPane对话框框架之间有填充(大约20px左右)之外,它按预期工作100%。

How can I get rid of this? 我怎么能摆脱这个?

Setting the border of the panel to an empty border with 0 as dimensions changed nothing. 将面板的边框设置为空边框,其中0作为尺寸没有任何改变。

Setting the border of the panel to an empty border with 0 as dimensions changed nothing. 将面板的边框设置为空边框,其中0作为尺寸没有任何改变。

You need to set the Border of the content pane of the dialog. 您需要设置对话框的内容窗格的边框。 Don't know if it will work on all LAF's but you can use the following for Metal and Windows: 不知道它是否适用于所有LAF,但您可以将以下内容用于Metal和Windows:

UIManager.put("OptionPane.border", new EmptyBorder(0, 0, 0, 0) );

See UIManager Defaults for more information. 有关更多信息,请参阅UIManager默认值

This will change the property for all option panes. 这将更改所有选项窗格的属性。 So you may want to save the default border, create your option pane and then restore the original border for creating other option panes. 因此,您可能希望保存默认边框,创建选项窗格,然后还原原始边框以创建其他选项窗格。

Maybe another option is to add an ContainerListener to the panel. 也许另一种选择是将ContainerListener添加到面板。 Then you could handle the componentAdded(...) event. 然后你可以处理componentAdded(...)事件。 When the event is generated you can get the parent panel and remove the Border. 生成事件后,您可以获取父面板并删除边框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM