This question already has an answer here:
这个问题在这里已有答案:
- AWT Frame in full-screen exclusive mode gets minimized on windows dialog popup 2 answers
全屏独占模式下的AWT帧在Windows对话框弹出2答案中最小化
I couldn't find any spesific solution for Fullscreen Window so I want to ask. How to make a JOptionPane on the top of a Fullscreen Window?
我找不到任何针对全屏窗口的特定解决方案,所以我想问一下。如何在全屏窗口的顶部创建一个JOptionPane?
In here , Im taking a Fullscreen window as a constructor parameter. But when I press ESC , my window sending itself to background, like I pressed "Alt+Tab". Then if I click on if from start menu bar , I can see it on top of window. But I want to end this sending background problem.How can I fix it?
在这里,我将全屏窗口作为构造函数参数。但是当我按下ESC时,我的窗口将自己发送到后台,就像我按下“Alt + Tab”一样。然后,如果我从开始菜单栏点击,我可以在窗口顶部看到它。但是我想结束这个发送背景问题。我该如何修复它?
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) {
}
}
And here is my code for making my window fullscreen
这是我的窗口全屏幕的代码
window=(Window)frame;
window.setFocusable(true);
KeyListenerTest keyo = new KeyListenerTest(window);
frame.addKeyListener(keyo);
g.setFullScreenWindow(window);
1 个解决方案
#1
Use:
frame.setSize(300, 200); //or any other size you want for JFrame after changeing from maximalized state
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
instead of:
g.setFullScreenWindow(window);
works for me.
适合我。
#1
Use:
frame.setSize(300, 200); //or any other size you want for JFrame after changeing from maximalized state
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
instead of:
g.setFullScreenWindow(window);
works for me.
适合我。