Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 459951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:49:27+00:00 2026-05-12T22:49:27+00:00

Simply stated, I am trying to make a game I am working on full-screen.

  • 0

Simply stated, I am trying to make a game I am working on full-screen.

I have the following code I am trying to use:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
if(!gs.isFullScreenSupported()) {
    System.out.println("full-screen not supported");
}

Frame frame = new Frame(gs.getDefaultConfiguration());
Window win = new Window(frame);

try {
    // Enter full-screen mode
    gs.setFullScreenWindow(win);
    win.validate();
}

Problem with this is that I am working within a class that extends JPanel, and while I have a variable of type Frame, I have none of type Window within the class.

My understanding of JPanel is that it is a Window of sorts, but I cannot pass ‘this’ into gs.setFullScreenWindow(Window win)… How should I go about doing this?

Is there any easy way of calling that, or a similar method, using a JPanel?

Is there a way I can get something of type Window from my JPanel?

–

EDIT: The following method changes the state of JFrame and is called every 10ms:

public void paintScreen()
{
    Graphics g;
    try{
        g = this.getGraphics(); //get Panel's graphic context
        if(g == null)
        {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
            frame.add(this);
            frame.pack();
            frame.setResizable(false);
            frame.setTitle("Game Window");
            frame.setVisible(true);
        }
        if((g != null) && (dbImage != null))
        {
            g.drawImage(dbImage, 0, 0, null);
        }
        Toolkit.getDefaultToolkit().sync(); //sync the display on some systems
        g.dispose();
    }
    catch (Exception e)
    {
        if(blockError)
        {
            blockError = false;
        }
        else
        {
            System.out.println("Graphics context error: " + e);
        }
    }
}

I anticipate that there may be a few redundancies or unnecessary calls after the if(g==null) statement (all the frame.somethingOrOther()s), any cleanup advice would be appreciated…

Also, the block error is what it seems. I am ignoring an error. The error only occurs once, and this works fine when setup to ignore the first instance of the error… For anyone interested I can post additional info there if anyone wants to see if that block can be removed, but i’m not concerned… I might look into it later.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:49:27+00:00Added an answer on May 12, 2026 at 10:49 pm

    Have you made any progress on this problem? It might be helpful if you could update your question with your expected behavior and what the code is actually doing? As was already pointed out, JFrame is a subclass of Window, so if you have a JFrame, you don’t need a Window.

    For what it’s worth, I have a Java app which works in fullscreen mode. Although the screen is not repainted as often as yours, it is repainted regularly. I do the following to enter fullscreen:

    // pseudo-code; not compilable
    
    JPanel container = new JPanel();
    container.setOpaque( true ); // make sure the container will be visible
    
    JFrame frame = new JFrame();
    frame.getContentPane().add(container); // add the container to the frame
    frame. ... //other initialization stuff, like default close operation, maximize, etc
    
    if ( fullScreenModeIsSupported )
        frame.setUndecorated( true ); // remove window decorations from the frame
        gs.setFullScreenWindow( frame );
        frame.validate();
    

    Then whenever I need to update the screen, I just plug a new JPanel into the container JPanel:

    // pseudo-code; not compilable
    
    container.removeAll(); // clean out the container
    container.add( jPanelWithNewDisplay ); // add the new display components to the container
    container.validate();  // update and redisplay
    container.repaint();
    

    Can’t claim that it’s technically perfect, but it works well for me. If the pseudo-code examples don’t cut it, I can spend some time putting together a compilable example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started trying to make a simple game with XNA 3.1 to
Question simple and quick: I have started to use Netbeans to write some code
I've been trying to make a little simple game just to test my logics,
I'm trying to animate object. I use keyframe animation: I have two vertex buffers
I am trying to make a Content Slider for my site. I have multiple
I trying to make a simple image gallery, where I have several radio button
I'm trying to make a small game using (free)GLUT. I know that it's old
I am trying to make a simple game that goes across a TCP network.
In C++ I'm trying to make a simple state machine for a game, based
I'm trying to make a little game that will first show the player a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.