简体   繁体   English

自定义JOptionPane

[英]Customizing JOptionPane

We are trying to customize a JOptionPane generated JDialog to have rounded corners. 我们正在尝试自定义JOptionPane生成的JDialog以使其具有圆角。 We have a JPanel implementation that has rounded corners. 我们有一个圆角的JPanel实现。 I am unable to find a way to integrate the rounded corners implementation into the JOptionPane/JDialog. 我找不到将圆角实现集成到JOptionPane / JDialog中的方法。

It would of great help if some one can point me into how I can fit the JDialog into a JPanel or some other way to do this. 如果有人可以指出我如何将JDialog装入JPanel或执行此操作的其他方法,那将有很大的帮助。

A JDialog is a top level component that can not be added anywhere. JDialog是无法在任何地方添加的顶级组件。 Although you can add the "content" of the JOptionPane , by using one of JOptionPane 's constructors . 尽管可以使用JOptionPane的构造函数之一添加JOptionPane的“内容”。

JOptionPane extends from JComponent . JOptionPaneJComponent扩展。 It provides convince methods to construct the JDialog which is displayed on the screen (containing an instance of JOptionPane ) 它提供了令人信服的方法来构造屏幕上显示的JDialog (包含JOptionPane的实例)

If you want to modify the look and feel of the JDialog , you need to create your own undecorated dialog and add the JOptionPane to it. 如果要修改JDialog的外观,则需要创建自己的未修饰对话框,然后向其添加JOptionPane

What I would suggest would be to create a number of static utility methods that mimic the JOptionPane showXxxMessage methods but which create the instance of the dialog you want and which then simply add an instance of the JOptionPane to. 我的建议是创建一些static实用程序方法,这些方法模仿JOptionPane showXxxMessage方法,但会创建所需对话框的实例,然后将JOptionPane的实例添加到其中。

You will need to attach a PropertyChangeListener to the JOptionPane to monitor when the user makes a selection though. 但是,您需要将PropertyChangeListener附加到JOptionPane以监视用户何时进行选择。

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

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