How can I create a Java Swing app that covers the Windows Title bar?

前端 未结 3 537
野的像风
野的像风 2021-01-06 02:35

I\'m working on a java swing application that will be used in a psychology experiment and the researchers have requested that I make the program \"black out the screen\" in

相关标签:
3条回答
  • 2021-01-06 02:40

    Use the setUndecorated(true) property. Note that this has to be done before making the frame visible.

    JFrame frame = new JFrame();
    Toolkit tk = Toolkit.getDefaultToolkit();
    frame.setBounds(new Rectangle(new Point(0, 0), tk.getScreenSize()));
    frame.setUndecorated(true);
    frame.setVisible(true);
    
    0 讨论(0)
  • 2021-01-06 02:41

    Use the Full Screen Java APIs?

    http://java.sun.com/docs/books/tutorial/extra/fullscreen/exclusivemode.html

    http://www.artificis.hu/2006/03/16/java-awtswing-fullscreen

    JFrame fr = new JFrame();
    fr.setResizable(false);
    if (!fr.isDisplayable()) {
        // Can only do this when the frame is not visible
        fr.setUndecorated(true);
    }
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    try {
      if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(fr);
      } else {
        // Can't run fullscreen, need to bodge around it (setSize to screen size, etc)
      }
      fr.setVisible(true);
      // Your business logic here
    } finally {
      gd.setFullScreenWindow(null);
    }
    
    0 讨论(0)
  • 2021-01-06 02:47

    I know this thread is old but I found it while searching on how to do the same thing myself. I couldn't find any solutions I wanted to use so I came up with this. I found that the below solution not only works but is also much simpler than the above answers.

    JFrame frame = new JFrame();
    frame.setResizable(false);
    frame.setUndecorated(true);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setSize(dim);
    frame.setVisible(true);
    
    0 讨论(0)
提交回复
热议问题