为什么Windows XP会在我的第二个屏幕上最小化我的摇摆全屏窗口?

时间:2008-09-10 11:47:56

标签: java windows swing

在我正在开发的应用程序中(在Java / swing中),我必须在用户的 second 屏幕上显示一个全屏窗口。 我使用类似于下面的代码来完成此操作... 是的,只要我在Windows资源管理器打开的窗口中单击,或者只要我打开Windows资源管理器(我使用的是Windows XP),全屏窗口就会最小化......

您是否知道解决此问题的方法或解决方法,或者是否有一些我不了解全屏窗口的重要内容?

感谢您的帮助,

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JWindow;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;

import javax.swing.JButton;
import javax.swing.JToggleButton;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import javax.swing.JLabel;

public class FullScreenTest {

    private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="94,35"
    private JPanel jContentPane = null;
    private JToggleButton jToggleButton = null;
    private JPanel jFSPanel = null;  //  @jve:decl-index=0:visual-constraint="392,37"
    private JLabel jLabel = null;
    private Window window;
    /**
     * This method initializes jFrame   
     *  
     * @return javax.swing.JFrame   
     */
    private JFrame getJFrame() {
        if (jFrame == null) {
            jFrame = new JFrame();
            jFrame.setSize(new Dimension(474, 105));
            jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jFrame.setContentPane(getJContentPane());
        }
        return jFrame;
    }

    /**
     * This method initializes jContentPane 
     *  
     * @return javax.swing.JPanel   
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.add(getJToggleButton(), null);
        }
        return jContentPane;
    }

    /**
     * This method initializes jToggleButton    
     *  
     * @return javax.swing.JToggleButton    
     */
    private JToggleButton getJToggleButton() {
        if (jToggleButton == null) {
            jToggleButton = new JToggleButton();
            jToggleButton.setBounds(new Rectangle(50, 23, 360, 28));
            jToggleButton.setText("Show Full Screen Window on 2nd screen");
            jToggleButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    showFullScreenWindow(jToggleButton.isSelected());
                }
            });
        }
        return jToggleButton;
    }

    protected void showFullScreenWindow(boolean b) {
        if(window==null){
            window = initFullScreenWindow();
        }
        window.setVisible(b);

    }

    private Window initFullScreenWindow() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gds = ge.getScreenDevices();
        GraphicsDevice gd = gds[1];
        JWindow window = new JWindow(gd.getDefaultConfiguration());
        window.setContentPane(getJFSPanel());
        gd.setFullScreenWindow(window);
        return window;
    }

    /**
     * This method initializes jFSPanel 
     *  
     * @return javax.swing.JPanel   
     */
    private JPanel getJFSPanel() {
        if (jFSPanel == null) {
            jLabel = new JLabel();
            jLabel.setBounds(new Rectangle(18, 19, 500, 66));
            jLabel.setText("Hello ! Now, juste open windows explorer and see what happens...");
            jFSPanel = new JPanel();
            jFSPanel.setLayout(null);
            jFSPanel.setSize(new Dimension(500, 107));
            jFSPanel.add(jLabel, null);
        }
        return jFSPanel;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        FullScreenTest me = new FullScreenTest();
        me.getJFrame().setVisible(true);

    }

}

2 个答案:

答案 0 :(得分:1)

通常,当应用程序处于“全屏”模式时,它将接管整个桌面。要让用户进入另一个窗口,他们必须使用alt-tab。此时,Windows将最小化全屏应用程序,以便其他应用程序可以到达前端。

这听起来像是Windows中的错误(未记录的功能......)。对于双屏设置,它可能不应该这样做。

解决此问题的一个选项是将窗口设置为“全屏”,而不是将窗口设置为与位置(0,0)的屏幕相同的大小。您可以从GraphicsConfigurations on the GraphicsDevice获取屏幕信息。

答案 1 :(得分:0)

以下代码有效(谢谢John)。没有全屏和大“永远在上面”的窗口。 但我仍然不知道为什么窗户造成了这种奇怪的行为......

private Window initFullScreenWindow() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    GraphicsDevice gd = gds[1];
    JWindow window = new JWindow(gd.getDefaultConfiguration());
    window.setContentPane(getJFSPanel());
    window.setLocation(1280, 0);
    window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight());
    window.setAlwaysOnTop(true);
    //gd.setFullScreenWindow(window);
    return window;
}