0

I am writing a reminder program that pops up message dialogs. The problem is that all of the dialogs appear right on top of each other. I would prefer to have them cascade. Normally with other programs a dialog will apear then the next one will be slightly down and off to the side. My code snippet is as follows:

final JFrame frame = new JFrame( "A timer to be a reminder" );
frame.setVisible( false ); 
frame.setAlwaysOnTop(true);
int result = JOptionPane.showConfirmDialog( frame, msg, "Timer", JOptionPane.DEFAULT_OPTION);

Can anyone point out how to get the desired behavior?

This has been solved, I am attaching my code snippet so that someone else will be able to find it.

JFrame frame = new JFrame( "A timer to be a reminder" );
frame.setLocationByPlatform( true );
frame.setVisible( true ); 
frame.setAlwaysOnTop(true);
int result = JOptionPane.showConfirmDialog( frame, msg, "Timer", JOptionPane.DEFAULT_OPTION);
frame.setVisible( false );
frame = null;
Goff
  • 343
  • 1
  • 3
  • 14
  • Possible duplicate of [How to set the location of "JOptionPane.showMessageDialog"](http://stackoverflow.com/questions/13760117/how-to-set-the-location-of-joptionpane-showmessagedialog) – Petter Friberg Nov 04 '15 at 19:39

1 Answers1

2

A JOptionPane is centered on the parent component or the center of the window if a null component is used.

To control placement you will need to use a custom JDialog. Then you can use:

dialog.setLocationByPlatform( true );

and the location will be determined by the fules of each platform for new windows.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Your answer lead me to the solution I settled on. I didn't really want to have to create a custom dialog but since you said it was based on the location of the frame I applied it to the frame. It does not work perfectly but it is more than suitable for me. I will attach my code snippet if any one is interested, will be edited into the main article. Thank you. – Goff Nov 04 '15 at 23:56