Making a Java panel fullscreen
Solution 1
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);
}
});
}
...
}
Solution 2
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);
}
Solution 3
You need to use the following API: http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html
Going full screen isn't as simple as making a large panel, you need to look into the underlying OS graphics. But your JPanel code should translate just fine.
Comments
-
clamp almost 4 years
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.
-
Connorelsea about 9 yearsCan you please explain why this works. Specifically the part in the runnable, such as the lines following
l.x -= p.x;
. It works, but I want to fully understand it as well. -
VonC about 9 years@Connorelsea It might be easier to ask that in a separate question: after 5+years, and don't remember all the details.