更新时间:2023-12-03 13:32:52
出现额外图标的原因与JDialog
无关.在您的JOptionPane
中,您正在创建new SelectionFrame()
The reason you have an extra icon, has nothing to do with the JDialog
. In you JOptionPane
, you're creating a new SelectionFrame()
response = JOptionPane.showConfirmDialog(new SelectionFrame("Selection"),
"Would you like to apply the policy attachment " + attachmentName + " to current instance (" + processInstance + ") of process " + processName + " ?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
您不需要这样做.您可以将SelectionFrame
传递给它.这是SelectionDialog
的构造函数的简单重构.它工作正常.而且,看起来setVisible
方法是不必要的.只需在其上调用dispose()
.
You don't need to do that. You can just pass the SelectionFrame
to it. Here's a simple refactor of the constructor for SelectionDialog
. It works fine. Also, it looks the the setVisible
method is unnecessary. Just call dispose()
on it.
public SelectionDialog(final JFrame frame, boolean modal, String attachmentName, Long processInstance, String processName) {
super(frame, modal);
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
response = JOptionPane.showConfirmDialog(frame, "Would you like to apply the policy attachment " + attachmentName + " to current instance (" + processInstance + ") of process " + processName + " ?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}
实例化它时,只需像这样
When you instantiate it, just do it like this
SelectionDialog dialog = new SelectionDialog(SelectionFrame.this, true,...)
旁注
老实说,如果您只想使用JOptionPane
,则根本没有理由使用JDialog
.您需要在一个或另一个之间做出决定.如果您选择JDialog
,则完全不要使用JOptionPane
,反之亦然.
I honestly see no reason for the JDialog
at all if you're just going to use a JOptionPane
. You need to decide between one or the other. If you go with the JDialog
then don't use the JOptionPane
at all, and vice versa.
在创建JDialog
时,最终只是在创建自定义JOptionPane
,因此当在JDialog
中使用JOptionPane
时,您将无法实现使用一个或另一个的目的.
When you're creating a JDialog
, you're ultimately just creating a custom JOptionPane
, so when you use a JOptionPane
inside a JDialog
you're defeating the purpose of using one or the other.