Perché Windows XP riduce a icona la finestra a schermo intero oscillante sul secondo schermo?

StackOverflow https://stackoverflow.com/questions/53820

  •  09-06-2019
  •  | 
  •  

Domanda

Nell'applicazione che sto sviluppando (in Java/swing), devo mostrare una finestra a schermo intero sul file secondo schermo dell'utente.L'ho fatto utilizzando un codice simile a quello che troverai qui sotto...Ad esempio, non appena faccio clic in una finestra aperta da Windows Explorer o non appena apro Windows Explorer (sto utilizzando Windows XP), la finestra a schermo intero viene ridotta a icona...

Conosci un modo o una soluzione alternativa per risolvere questo problema o c'è qualcosa di importante che non ho capito con le finestre a schermo intero?

Grazie per l'aiuto,

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

    }

}
È stato utile?

Soluzione

Di solito, quando un'applicazione è in modalità "schermo intero", occuperà l'intero desktop.Affinché un utente possa accedere a un'altra finestra, dovrebbe premere alt-tab su di essa.A quel punto Windows minimizzerebbe l'app a schermo intero in modo che l'altra applicazione possa venire in primo piano.

Sembra che potrebbe trattarsi di un bug (funzionalità non documentata...) in Windows.Probabilmente non dovrebbe farlo per una configurazione a doppio schermo.

Un'opzione per risolvere questo problema è invece di impostarlo su "schermo intero", semplicemente rendere la finestra della stessa dimensione dello schermo con posizione (0,0).È possibile ottenere informazioni sullo schermo da GraphicsConfigurations sul GraphicsDevice.

Altri suggerimenti

Il seguente codice funziona (grazie John).Senza schermo intero e una grande finestra "sempre in primo piano".Ma ancora non so perché Windows abbia causato questo strano comportamento...

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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top