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

  • Home
  • SEARCH
  • 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 9294257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:19:47+00:00 2026-06-18T21:19:47+00:00

Originally (See my previous question Java how to make JFrames start off as a

  • 0

Originally (See my previous question “Java how to make JFrames start off as a maximised window“) I wanted to make a window which starts out maximised.
This code accomplishes this:

public static void main(String[] args)  {

JFrame frame = new JFrame();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);

}

However, if this window is restored down it becomes a practically non-existent bar. To solve this I set a size for the window using setSize(). This works but presents another problem, the window can still be resized.

To solve this problem I set setResizable(false); and this is my code so far:

public static void main(String[] args) {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    JFrame frame = new JFrame("Jedia");
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setSize(screenSize);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

However, now the window starts out at its specified size (rather than maximised) and cannot be restored up.

So, my question is, how can I either make the window start out maximised, give it a size for when it is restored down and make resizing it impossible? Or make a window that starts out maximised and cannot be restored down?

  • 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-06-18T21:19:48+00:00Added an answer on June 18, 2026 at 9:19 pm

    There is a simple fix that works almost all the time: make your frame not resizable after having set visible. So only modifies your code this way:

    public static void main(String[] args) {
    
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    
        JFrame frame = new JFrame("Jedia");
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setSize(screenSize);
        frame.setVisible(true);    // FIRST visible = true
        frame.setResizable(false); // THEN  resizable = false
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    }
    

    This way, the frame will start maximized and the maximize button will be greyed out, preventing user to use it. (I don’t really know why you have to do this. I suppose the maximized state is really applied only when the window becomes visible, and if you make it unresizable before, it will not apply.)

    It works almost all the time because on Windows 7 at least you can make the window goes out of the maximized state by clicking the title bar and dragging it. But it will be at the size you have set it earlier. Problem is that your user will not be able to maximize it again, and I haven’t found the way with listeners to make the window back to maximized state. ( Edit: @David Kroukamp shows in the last part of his answer that it is possible to force the maximized state by using a ComponentListener. Therefore you don’t have to use setResizable(false) This way you still have a problem with Windows 7 because the dragging action is not catched by this event for whatever reason but users will be able to use the maximized button to put it back where it should be.)

    Now, there is almost never a reason to do this kind of things. Users don’t really like when you prevent them to manipulate their windows (maximized windows can not be moved, for example, and that can be annoying when you have multiple screens). An exception is if you are making a game, which is typically full-screen. But then you wouldn’t want a JFrame because you don’t want all the decoration, but a Window.

    If your problem is that the default window size is very small, it’s normal. You have to put something in your frame first (some controls, buttons, what you want in your application), using layouts (that’s important) then call the method pack() on your frame. It will chose a nice default size for your window.

    Finally, a last word. I’ve put my example code in a main method as a shortcut, but you should always do Swing stuff in the Swing EDT by using SwingUtils.invokeLater().

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

Sidebar

Related Questions

I have the lovely functions from my previous question , which work fine if
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
Originally posted on Server Fault , where it was suggested this question might better
I originally started this question in another thread, but that thread was sorta, kinda
I originally setup some conditions using CGRectIntersectsRect for some collision detection which worked fine.
This is related to a previous question I asked about conditionally sending document data
To follow from my previous question about virtual and multiple inheritance (in a cross
In my previous question How to find the unique serial number of a flash
Okay, so if you would like a back story, look at my previous question
Thanks to the help in a previous question , I've got the following code

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.