0

Say I have a class MyDialogClass extends JDialog, which I use everywhere in my application, in order to acheive some specific behaviour of my dialogs. Now, I also want to enjoy the benefits of JOptionPane utilities, and call showXxxDialog to view messages / errors etc., but I still want the underlying dialogs to behave as a MyDialogClass instances.

Is it possible to achive (prefferably without deeply replicating the source of JOptionPane)?

EDIT:

The specific behaviour I am trying to acheive is setting the dialog alwaysOnTop to true. I will try @Andrew's solution for this issue. BUT, this is only the current problem I'm facing, and not the only extended behaviour in MyDialogClass. So there might be such "workaround" for every single problem, but I was intentionaly looking for a conceptual solution, which is the reason for putting my question as I originally did.

[[For instance - MyDialogClass also registeres a WindowListener to it's instances in the constructor]]

Elist
  • 5,313
  • 3
  • 35
  • 73

2 Answers2

2

You can display a JDialog in a JOptionPane, as shown in How to Make Dialogs: Stopping Automatic Dialog Closing.

In this case, you must implement your own property change listener so that when the user clicks a button, the dialog does not automatically close.

Related examples are seen here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

I'm not sure what you really want .. Do you want to use a dialog from JOptionPane but using your own JPanel? Did you try:

Object[] options = { "Yes", "No", "Cancel" };
JOptionPane.showOptionDialog(JFrame, YOURPANEL, "Information",
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
cslz
  • 1
  • I want more then my own panel, I want my own dialog class. Something like: `JOptionPane.showOptionDialog(JFrame, MyDialogClass.class, "Information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);` What I'm realy trying to do, in this case, is call the dialog's `setAlwaysOnTop(true)`. – Elist Oct 20 '14 at 11:11
  • 1
    *"is call the dialog's `setAlwaysOnTop(true).`"* The solution is to provide a parent component that is always on top. – Andrew Thompson Oct 20 '14 at 11:25