gpt4 book ai didi

java - 如何使 JOptionPane 位于全屏窗口之上?

转载 作者:行者123 更新时间:2023-12-01 11:34:34 25 4
gpt4 key购买 nike

我找不到全屏窗口的任何具体解决方案,所以我想问一下。如何在全屏窗口顶部制作 JOptionPane?

在这里,我将全屏窗口作为构造函数参数。但是当我按 ESC 时,我的窗口将自身发送到后台,就像我按“Alt+Tab”一样。然后,如果我从开始菜单栏单击 if ,我可以在窗口顶部看到它。但我想解决这个发送后台问题。我该如何解决它?

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import java.awt.*;

public class KeyListenerTest extends JFrame implements KeyListener {
private Window windo;
private ImageIcon quitImage;

public KeyListenerTest(Window window)
{
quitImage = new ImageIcon("quitask.png");
windo = window;
addKeyListener(this);
}

public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
JOptionPane opti = new JOptionPane();
int choice = opti.showConfirmDialog(windo, "Do you really want to quit?", "QUIT", JOptionPane.YES_NO_OPTION ,
JOptionPane.QUESTION_MESSAGE , quitImage);
opti.requestFocusInWindow();
if(choice == JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
{
dispose();
System.out.println("ESC key typed");
}
}
}
public void keyTyped(KeyEvent e) {
}

public void keyReleased(KeyEvent e) {
}
}

这是我使窗口全屏显示的代码

  window=(Window)frame;
window.setFocusable(true);

KeyListenerTest keyo = new KeyListenerTest(window);
frame.addKeyListener(keyo);

g.setFullScreenWindow(window);

最佳答案

用途:

frame.setSize(300, 200); //or any other size you want for JFrame after changeing from maximalized state
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

而不是:

g.setFullScreenWindow(window);

对我有用。

关于java - 如何使 JOptionPane 位于全屏窗口之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30139726/

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