2

I want to display a JDialog so I use this:

SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() { new DialogBox().setVisible(true); }
});

It works fine to display it but then my JDialog doesn't keep the focus, which it needs to (the user should not be able to work using the main UI while that dialog is open).

Is it safe to get rid of the SwingUtilities.invokeLater()?

Oh and according to this question it is not wise to extend JDialog or JFrame, why? That's how I've always done it.

Community
  • 1
  • 1
ldam
  • 4,412
  • 6
  • 45
  • 76
  • 1
    Don't you just want a modal dialog? – JB Nizet Apr 17 '13 at 21:08
  • Extending a JDialog or JFrame comes down to design. What functionality are you actually adding to these top level containers? Here is also the consideration that if you build you UI directly on top of one of these top level containers, you are restricting the use of your UI components in the future. Better to extend something like JPanel, build your UI on top of this, providing the required accessors and place it ontop of an instance of the required top level container – MadProgrammer Apr 17 '13 at 21:15

1 Answers1

1

It works fine to display it but then my JDialog doesn't keep the focus, which it needs to (the user should not be able to work using the main UI while that dialog is open).

have to setModal(true) or setModalityTypes(various types) for parent, or all windows from current JVM

Is it safe to get rid of the SwingUtilities.invokeLater()

yes exactly, all Top-Level Container should be created on EDT, wrapped in invokeLater(), including JOptionPane

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319