We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Java Fullscreen Application

Ulfsark asked
Medium Priority
Last Modified: 2012-06-27
Ok, I'm building a Java App in fullscreen mode. I've got the fullscreen mode working on a JFrame object with a JPanel added to it for content. What I need to know is how to swap the JPanel for a different one without dropping out of fullscreen mode. I suspect this has something to do with the BufferStrategy class, but I can't get it to work.

Here's what I've got so far, with a MyPanel jsut being a simple JPanel with an image and a settable background color. It should show the red one, wait around for a sec, then show the blue one. Currently it jsut shows the red one then a blank screen.

public static void main(String args[]) {
      try {
                GraphicsDevice screen = screenSetup();
            DisplayMode dmode = new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
            JFrame frame = makeFrame();

            MyPanel pan1 = testPanel(Color.RED);
            MyPanel pan2 = testPanel(Color.BLUE);

              Container conpane = frame.getContentPane();
            conpane.add(pan1, BorderLayout.CENTER);


            BufferStrategy bufstrat = frame.getBufferStrategy();
            Graphics g = bufstrat.getDrawGraphics();

            Rectangle bounds = frame.getBounds();
            javax.swing.SwingUtilities.paintComponent(g, pan2, conpane, bounds);

      } catch (Exception ex) {

Watch Question


Oh, sorry, here's the rest of the methods if they help.

      private static GraphicsDevice screenSetup() {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice[] gs = ge.getScreenDevices();
            GraphicsDevice gdev = gs[0];
            return gdev;


      public static JFrame makeFrame() {
            JFrame frame = new JFrame();
            return frame;


      public static MyPanel testPanel(Color c) {
            MyPanel panel = new MyPanel();
            JLabel lab = new JLabel(new ImageIcon("images/loading-screen.gif"));
            panel.add(lab, BorderLayout.CENTER);
            return panel;
Top Expert 2006

you can use something like this:
          conpane.add(pan2, BorderLayout.CENTER);
Top Expert 2006
Unlock this solution and get a sample of our free trial.
(No credit card required)
Top Expert 2006

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.