This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Maximizing a form (JFrame) by default when it opens Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Maximizing a form (JFrame) by default when it opens" Watch "Maximizing a form (JFrame) by default when it opens" New topic
Author

Maximizing a form (JFrame) by default when it opens

Tim Batts
Greenhorn

Joined: Aug 09, 2010
Posts: 10
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

What happens if you move that statement to after the pack() statement?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tim Batts
Greenhorn

Joined: Aug 09, 2010
Posts: 10
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.
 
Consider Paul's rocket mass heater.
 
subject: Maximizing a form (JFrame) by default when it opens
 
Similar Threads
can't add to JPanel after removeAll() is triggered by another swing component
How can i display minimize and iconifiable button in JInternalFrame
JPanel Form Problems
The panel refuses to show
running a video instance