Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 order that there should be no outside stimuli for the user. They want the swing app to be truly full-screen and without any type of title bar or minimize/maximize/close buttons on the top.

The software will be running in a Windows XP environment using JavaSE 6.

How can I do this and please provide a code snippet if applicable.

Thanks!

like image 248
HipsterZipster Avatar asked Apr 06 '09 19:04

HipsterZipster


People also ask

How do I change the color of the title bar in Java Swing?

put("JFrame. activeTitleBackground", Color. red); for change the toolbar color in JFrame.

Is Java swing a front end?

Swing API is a set of extensible GUI Components to ease the developer's life to create JAVA based Front End/GUI Applications. It is build on top of AWT API and acts as a replacement of AWT API, since it has almost every control corresponding to AWT controls.


2 Answers

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);
}
like image 90
JeeBee Avatar answered Sep 20 '22 11:09

JeeBee


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);
like image 37
erickson Avatar answered Sep 20 '22 11:09

erickson