Is there any way to create a full-screen (non-windowed) application in Java?

Nicola Ken Barozzi

Yes and no.

Yes because Java has components that are non-windowed. Ironically these are called Window (AWT) and JWindow (Swing).

No because in Microsoft Windows the "Start bar" remains top-level and overlaps with your Window.

Other platforms may have the same problem. Note that you may be able to get a truly full-screen application by using JNI to call native methods on your platform, but that kills portability of your application.

Here is the AWT code to make a Window as large as the screen.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FullscreenWindowApp extends Window {
  private Button button;

  public FullscreenWindowApp() {
    super(new Frame());
    button = new Button("Close");

    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
      }});

    setLayout(new FlowLayout());
    add(button);

    //get the screen size
    Dimension screenSize = 
        Toolkit.getDefaultToolkit().getScreenSize();

    //sets the location of the window to top left of screen
    setBounds(0,0,screenSize.width, screenSize.height);
  }

  public static void main(String[] args) {
    new FullscreenWindowApp().setVisible(true);
  }

}

The Swing code is nearly the same, using JWindow instead of Window,

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact