Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maximizing a form (JFrame) by default when it opens

 
Tim Batts
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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?

 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic