JAVA消息对话框一个在另一个上面



我正在编写一个弹出消息对话框的提醒程序。问题是所有的对话框都显示在一个对话框的正上方。我更喜欢它们级联。通常,对于其他程序,会出现一个对话框,然后下一个对话框会稍微向下倾斜。我的代码片段如下:

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);

有人能指出如何得到想要的行为吗?

这个问题已经解决了,我附上了我的代码片段,这样其他人就能找到它。

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;

如果使用空组件,则JOptionPane位于父组件的中心或窗口的中心。

要控制放置,您需要使用自定义JDialog。然后你可以使用:

dialog.setLocationByPlatform( true );

并且位置将由用于新窗口的每个平台的fules来确定。

最新更新