Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Java panel fullscreen

How would you make a JComponent (panel, frame, window, etc.) fullscreen, so that it also overlaps everything on the screen including the windows start bar?

I don't want to change the resolution or anything with the graphics device like bitdepth etc, I just want to overlap everything else.

like image 820
clamp Avatar asked Feb 27 '10 18:02

clamp


People also ask

How do I make JPanel full screen?

If you just want to display the frame maximized the code is: frame. setExtendedState(JFrame. MAXIMIZED_BOTH); frame.

How do you make a JFrame fit the screen?

Select all components of JFrame, right click, select 'Auto Resizing', check for both Horizontal and Vertical, close . Show activity on this post. Calling pack() will usually result in the window being resized to fit the contents' preferred size.

How do you make a panel visible in Java?

You can't display a panel on its own; it has to be added to a container, of which the most popular type is the JFrame. You are also supposed to start a new thread; the details are in the API for any Swing class, where the link to "Swing threading policy" is.


2 Answers

Check out this tutorial describing Java's Full-Screen mode API.

Example code (taken from the tutorial). Note that the code operates on a Window so you would need to embed your JPanel with a Window (e.g. JFrame) in order to do this.

GraphicsDevice myDevice;
Window myWindow;

try {
    myDevice.setFullScreenWindow(myWindow);
    ...
} finally {
    myDevice.setFullScreenWindow(null);
}
like image 116
Adamski Avatar answered Sep 25 '22 05:09

Adamski


You can try some of the codes in this page, allowing a container to fill the screen (so it is not a solution for an individual component, but for a set of components within a container like a JFrame)

public class MainWindow extends JFrame
{
  public MainWindow()
  {
    super("Fullscreen");
    getContentPane().setPreferredSize( Toolkit.getDefaultToolkit().getScreenSize());
    pack();
    setResizable(false);
    show();

    SwingUtilities.invokeLater(new Runnable() {
      public void run()
      {
        Point p = new Point(0, 0);
        SwingUtilities.convertPointToScreen(p, getContentPane());
        Point l = getLocation();
        l.x -= p.x;
        l.y -= p.y;
        setLocation(l);
      }
    });
  }
  ...
}
like image 25
VonC Avatar answered Sep 26 '22 05:09

VonC