Java全屏jframe与双显示器

你好亲爱的StackOverFlow老乡

我希望那个伟大的网站上有人可以帮助我。

在这里我的问题,我有2个Jframe,一个用于控制,一个用于向公众显示。 我需要在全屏显示框架,以避免公众看到它不需要的东西,我需要控制框架在另一个屏幕上可用来控制显示框架。

这是我的问题,今天,我在Ubuntu和双屏模式下工作没有问题,但在Windows 7的商业版本64(不要尝试其他版本)显示帧实际上全屏,但当我点击任何地方以外显示框(控制框包括),显示框自动最小化。 我客人这是一个与Windows最小化问题最大化的问题,但我真的想使它的工作。 我知道一个非常肮脏的解决方法,在于使显示框架成为我的屏幕大小,并将显示框架定位在良好的坐标上。

以下是我所做的示例代码。
要将显示框全屏显示,请将控制框对焦并按F11键 。 或使用菜单(法语)

GameFrame.java 等同于显示帧

package ihm; import java.awt.Graphics; import java.awt.Image; import javax.swing.plaf.basic.BasicTabbedPaneUI; public class GameFrame extends javax.swing.JFrame { public GameFrame() { initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { mainPanel = new javax.swing.JTabbedPane(); gamePanel = new javax.swing.JPanel(){ public void paintComponent(Graphics g){ super.paintComponent(g); if(backgroundImage != null){ g.drawImage(backgroundImage, 0, 0, this.getWidth(),this.getHeight(),null); } } }; votePanel = new javax.swing.JPanel(); countdownPanel = new javax.swing.JPanel(); bienvenuePanel = new javax.swing.JPanel(); adsPanel = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("ImproAffichage"); setAlwaysOnTop(true); setBackground(new java.awt.Color(255, 179, 0)); setForeground(java.awt.Color.white); setUndecorated(true); getContentPane().setLayout(new java.awt.GridLayout(1, 1)); mainPanel.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT); gamePanel.setBackground(new java.awt.Color(255, 168, 0)); gamePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(40, 40, 40, 40)); gamePanel.setMinimumSize(new java.awt.Dimension(200, 200)); gamePanel.setLayout(new java.awt.GridLayout(2, 2, 70, 70)); mainPanel.addTab("score", gamePanel); votePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)); votePanel.setLayout(new java.awt.GridLayout(1, 0)); mainPanel.addTab("vote", votePanel); countdownPanel.setLayout(new java.awt.GridLayout(1, 0)); mainPanel.addTab("decompte", countdownPanel); bienvenuePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)); bienvenuePanel.setLayout(new java.awt.GridLayout(1, 0)); mainPanel.addTab("Bienvenue", bienvenuePanel); adsPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)); adsPanel.setLayout(new java.awt.GridLayout(1, 0)); mainPanel.addTab("publicité", adsPanel); getContentPane().add(mainPanel); mainPanel.setUI(new BasicTabbedPaneUI() { protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_height) { return 0; } }); pack(); } public static void main(String args[]) { /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GameFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GameFrame().setVisible(true); } }); } private static GameFrame instance; private Image backgroundImage; private Image decompteImage; private Image bienvenueImage; // Variables declaration - do not modify private javax.swing.JPanel adsPanel; private javax.swing.JPanel bienvenuePanel; private javax.swing.JPanel countdownPanel; private javax.swing.JPanel gamePanel; private javax.swing.JTabbedPane mainPanel; private javax.swing.JPanel votePanel; // End of variables declaration public static GameFrame getInstance() { if (instance == null) { instance = new GameFrame(); } return instance; } public void refresh() { this.validate(); this.repaint(); this.pack(); } } 

ControlFrame.java 等同于控制框架

 package ihm; import java.awt.Dimension; import java.awt.GraphicsDevice; public class ControlFrame extends javax.swing.JFrame { public static ControlFrame getInstance() { if (instance == null) { instance = new ControlFrame(); } return instance; } private ControlFrame() { this.gameFrame = GameFrame.getInstance(); this.gameFrame.setBounds(100, 100, 400, 300); this.gameFrame.pack(); this.gameFrame.setVisible(true); initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { transitionPanel = new javax.swing.JPanel(); jbBienvenue = new javax.swing.JButton(); jbScore = new javax.swing.JButton(); jbVote = new javax.swing.JButton(); jbDecompte = new javax.swing.JButton(); jbPublicite = new javax.swing.JButton(); jpPlayerControl = new javax.swing.JPanel(); jMenuBar1 = new javax.swing.JMenuBar(); mainMenu = new javax.swing.JMenu(); jmScore = new javax.swing.JMenu(); jmiAddTeam = new javax.swing.JMenuItem(); jmiFullscreen = new javax.swing.JMenuItem(); jmiBackground = new javax.swing.JMenuItem(); jMenuItem1 = new javax.swing.JMenuItem(); jmiPointPath = new javax.swing.JMenuItem(); jmOtherImage = new javax.swing.JMenu(); jmiVote = new javax.swing.JMenuItem(); jmiDecompte = new javax.swing.JMenuItem(); jmiBienvenue = new javax.swing.JMenuItem(); jmiAds = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("ImproContro"); setAlwaysOnTop(true); setBounds(new java.awt.Rectangle(0, 0, 200, 300)); setForeground(java.awt.Color.white); setPreferredSize(new java.awt.Dimension(400, 500)); setResizable(false); getContentPane().setLayout(new java.awt.BorderLayout(25, 25)); transitionPanel.setLayout(new java.awt.GridLayout(1, 6)); jbBienvenue.setText("Bienvenue"); transitionPanel.add(jbBienvenue); jbScore.setText("Score"); transitionPanel.add(jbScore); jbVote.setText("Aux votes"); transitionPanel.add(jbVote); jbDecompte.setText("Decompte"); transitionPanel.add(jbDecompte); jbPublicite.setText("Publicité"); transitionPanel.add(jbPublicite); getContentPane().add(transitionPanel, java.awt.BorderLayout.PAGE_START); jpPlayerControl.setBackground(new java.awt.Color(255, 220, 0)); jpPlayerControl.setLayout(new java.awt.GridLayout(2, 2, 10, 10)); getContentPane().add(jpPlayerControl, java.awt.BorderLayout.CENTER); mainMenu.setText("File"); jMenuBar1.add(mainMenu); jmScore.setText("Score"); jmiAddTeam.setText("ajouter equipe"); jmScore.add(jmiAddTeam); jmiFullscreen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, 0)); jmiFullscreen.setText("Plein Ecran"); jmScore.add(jmiFullscreen); jmiBackground.setText("image \"fond score\""); jmScore.add(jmiBackground); jMenuItem1.setText("couleur \"fond score\""); jmScore.add(jMenuItem1); jmiPointPath.setText("Icone de point"); jmScore.add(jmiPointPath); jMenuBar1.add(jmScore); jmOtherImage.setText("Autre images"); jmiVote.setText("image \"aux votes\""); jmOtherImage.add(jmiVote); jmiDecompte.setText("image \"fond Decompte\""); jmOtherImage.add(jmiDecompte); jmiBienvenue.setText("image \"Bienvenue\""); jmOtherImage.add(jmiBienvenue); jmiAds.setText("Ajouter image annonce"); jmOtherImage.add(jmiAds); jMenuBar1.add(jmOtherImage); setJMenuBar(jMenuBar1); jmiFullscreen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, 0)); jmiFullscreen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmiFullscreenActionPerformed(evt); } }); pack(); } /** * @param args the command line arguments */ public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ControlFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ControlFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ControlFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ControlFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } /* * * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { ControlFrame.getInstance().setVisible(true); } }); } private void jmiFullscreenActionPerformed(java.awt.event.ActionEvent evt) { GraphicsDevice gd = this.gameFrame.getGraphicsConfiguration().getDevice(); if (gd.getFullScreenWindow() != null) { gd.setFullScreenWindow(null); this.gameFrame.setResizable(true); this.gameFrame.setPreferredSize(new Dimension(400, 300)); } else { this.gameFrame.setResizable(false); this.gameFrame.setPreferredSize(new Dimension(gd.getDefaultConfiguration().getBounds().getSize())); this.gameFrame.enableInputMethods(false); gd.setFullScreenWindow(this.gameFrame); } refresh(); } private static ControlFrame instance; private GameFrame gameFrame; // Variables declaration - do not modify private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JButton jbBienvenue; private javax.swing.JButton jbDecompte; private javax.swing.JButton jbPublicite; private javax.swing.JButton jbScore; private javax.swing.JButton jbVote; private javax.swing.JMenu jmOtherImage; private javax.swing.JMenu jmScore; private javax.swing.JMenuItem jmiAddTeam; private javax.swing.JMenuItem jmiAds; private javax.swing.JMenuItem jmiBackground; private javax.swing.JMenuItem jmiBienvenue; private javax.swing.JMenuItem jmiDecompte; private javax.swing.JMenuItem jmiFullscreen; private javax.swing.JMenuItem jmiPointPath; private javax.swing.JMenuItem jmiVote; private javax.swing.JPanel jpPlayerControl; private javax.swing.JMenu mainMenu; private javax.swing.JPanel transitionPanel; // End of variables declaration public void refresh() { System.out.println("refresh()"); this.gameFrame.refresh(); this.validate(); this.repaint(); } } 

EDIT1:
我尝试全屏显示这两个窗口,但是当调用一个文件select器时,焦点会丢失,因为全屏窗口始终处于顶级行为状态。

编辑2:
我也试图把一个监听器放在图标显示jframe,但如果我试图改变状态为正常,显示jframe请求焦点,我的第二帧不能使用,因为它失去了焦点

编辑3:
如果显示框没有被全屏显示,那么点击控制框时不会最小化。

下午好

Kiwy

Solutions Collecting From Web of "Java全屏jframe与双显示器"

所以在这里,我自己的anwser到我自己的问题,我终于使用的解决方法,我认为是唯一没有这么丑陋的解决方法,我可以找到是使用此代码

 private void jmiFullscreenActionPerformed(java.awt.event.ActionEvent evt) { GraphicsDevice gd = this.gameFrame.getGraphicsConfiguration().getDevice(); if (!this.gameFrame.isResizable() ) { //gd.setFullScreenWindow(null); this.gameFrame.setResizable(true); this.gameFrame.setPreferredSize(new Dimension(400, 300)); } else { this.gameFrame.setResizable(false); this.gameFrame.setPreferredSize(new Dimension(gd.getDefaultConfiguration().getBounds().getSize())); this.gameFrame.setExtendedState(Frame.MAXIMIZED_BOTH); } refresh(); } 

而不是我原来的例子

 private void jmiFullscreenActionPerformed(java.awt.event.ActionEvent evt) { GraphicsDevice gd = this.gameFrame.getGraphicsConfiguration().getDevice(); if (gd.getFullScreenWindow() != null) { gd.setFullScreenWindow(null); this.gameFrame.setResizable(true); this.gameFrame.setPreferredSize(new Dimension(400, 300)); } else { this.gameFrame.setResizable(false); this.gameFrame.setPreferredSize(new Dimension(gd.getDefaultConfiguration().getBounds().getSize())); this.gameFrame.enableInputMethods(false); gd.setFullScreenWindow(this.gameFrame); } refresh(); } 

所以最后我不使用java全屏功能,我只是使用我的jframe的一些属性,使其看起来像一个全屏的框架。

希望它帮助你们中的一些人! 祝你今天愉快