Question

I have an application that uses the JOptionPane.show* methods to inform the user about various conditions before displaying the applications main window. On a multi screen setup these always show on the first screen. This is usually only a minor annoyance, but becomes a problem when the 0 screen is off or disconnected.

Normal windows can be placed correctly using the GraphicsConfiguration obtained via MouseInfo, but I can't find a way to pass that to JOptionPane. I can not either use the main window to anchor the dialogs, because there is no main window at that stage of the application startup. Among the possible dialogs is a warning about obsolete java versions, so displaying the main window before the errors is not option since the user's java runtime may not even be capable of displaying the main window.

Is there a way to specify the target screen without reimplementing a major part of JOptionPane?

Was it helpful?

Solution

You can create a JDialog out of a JOptionPane, and then display the dialog any location that you desire.

As per the JOptoinPane API:

 JOptionPane pane = new JOptionPane(arguments);
 pane.set.Xxxx(...); // Configure
 JDialog dialog = pane.createDialog(parentComponent, title);
 // here set the dialog's location
 dialog.setVisible(true);

Edit: Alternatively, you could simply create your own JDialog window de novo as per Andrew's great comment (that now no longer exists?).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top