Reputation: 23
i have displyed this JDialog
, and have passed an Object which is a JPanel
on it , thus my JDialog
displays my JPanel
on it when Invoked as required.
and on this JPanel
I have a JButton
, on pressing i want some operations to happen which i have written in it's ActionListener
and in the end i have to dispose that JDialog
, but i have no clue how to do it !!
This s my JDialog
Statement and help me with HOW TO EVEN REMOVE AN ICON from JDialog
as even after keeping the ICON PARAMETER NULL it displays the ICON.
JOptionPane.showOptionDialog(null, "SELECT ITEM AND THEN EDIT THE DETAILS.",
"EDIT ITEM DETAILS", int1, int2 , null, objEditMorePane, null);
Upvotes: 0
Views: 310
Reputation: 1553
You'll need to keep a reference to the dialog if you want to close it yourself. See the Oracle tutorial on custom Dialog
s. The constructor you're using also puts in an icon by default; if you make your own dialog, you can control that part too.
Upvotes: 1
Reputation: 44414
JOptionPane closes its dialog when its value
property changes. So, you can obtain the parent JOptionPane and set its value to close the window:
JOptionPane optionPane = (JOptionPane)
SwingUtilities.getAncestorOfClass(JOptionPane.class, button);
optionPane.setValue(JOptionPane.CLOSED_OPTION);
If the window wasn't created by JOptionPane, you can use the getTopLevelAncestor
method of JComponent to obtain the parent window:
Window window = (Window) button.getTopLevelAncestor();
window.dispose();
Upvotes: 0
Reputation: 37875
It sounds like you want to make it a JOptionPane.PLAIN_MESSAGE. That is what you need to put instead of whatever int2 is. I was going to link you to the tutorial but Space Pope already did that. You don't need to create a custom dialog to change the default icon, just change the message type to a plain message. The tutorial covers all this stuff.
Upvotes: 1