gpt4 book ai didi

JAVA 消息对话框出现在彼此之上

转载 作者:行者123 更新时间:2023-12-02 04:13:49 30 4
gpt4 key购买 nike

我正在编写一个弹出消息对话框的提醒程序。问题是所有对话框都出现在彼此的顶部。我更喜欢让它们级联。通常,对于其他程序,会出现一个对话框,然后下一个对话框会稍微向下并偏离一侧。我的代码片段如下:

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

位置将根据新窗口各平台的功能来确定。

关于JAVA 消息对话框出现在彼此之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33530462/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com