Specifying the target screen of a single JOptionPane

I have an application that uses the JOptionPane.show* to inform the user about various conditions before displaying the main application window. When setting up multiple screens, they are always displayed on the first screen. This is usually a minor annoyance, but it becomes a problem when screen 0 is turned off or off.

Normal windows can be positioned correctly using the resulting GraphicsConfiguration via MouseInfo , but I cannot find a way to pass this to JOptionPane . I can not use the main window to bind dialogs, because there is no main window at this stage of the application launch. Among the possible dialogs there is a warning about outdated versions of Java, therefore, displaying the main window before errors is not an option, since the java user environment may not even be able to display the main window.

Is there a way to specify the target screen without overriding the main body of JOptionPane ?

+4
source share
1 answer

You can create a JDialog from JOptionPane, and then display the dialog anywhere you want.

According to the JOptoinPane API :

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

Edit: Alternatively, you can simply create your own JDialog de novo window according to Andrew's wonderful remark (which now no longer exists?).

+3
source

Source: https://habr.com/ru/post/1493814/


All Articles