• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Maximizing a form (JFrame) by default when it opens

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am generating a swing JFrame via NetBeans and the goal is to get it to maximize automatically when the JFrame opens. JFrame is implemented as a class extension of javax.swing.JFrame.

I thought setExtendedState(JFrame.MAXIMIZE_BOTH); would work, but it isn't. Can anyone help?

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you move that statement to after the pack() statement?
 
Tim Batts
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't. The IDE won't let me edit the generated code. Which I think is stupid.

I did find a work around: the generated code for the main is this:


I replaced it with the following to actually set a reference variable for the form:

But I don't understand why running that statement in the constructor would not have maximized the frame. I would think it would work no differently than the previous statement setDefaultCloseOperation and should execute.

Altering the main as I did works, but if someone can confirm for me if that will have other consequences for the application I would appreciate it. Or if there is another way to do it.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic