Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maximize JFrame from code

 
Marcus Rag
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am new to the forum, so I apologize for any daft moments :)

I searched for this topic and only got topic on disabling the maximize button, so here goes.

I need to set my jFrame (which is also my main class) to maximize in startup. To set it to be the same size as the screen is not good enough, because that means that someone might accidentally move it.

Any suggestions?

Thanks,
Marcus
 
Rob Camick
Ranch Hand
Posts: 2612
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Marcus Rag
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,

but where in my code do I put this?

cheers
 
Rob Camick
Ranch Hand
Posts: 2612
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Experiment. How long does it take to add that line of code in your program to see what it does.
 
Marcus Rag
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already have experimented...and it takes very long. I constantly get the error that the non-static method can not be referenced from a static contexted...
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either call frame.setExtendedState(...) where frame is your JFrame instance, or call it inside an instance method of the JFrame. That's not so hard, is it?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I constantly get the error that the non-static method can not be referenced from a static contexted...

I'd also suggest you forget about GUI's until you understand the fundamentals of the language.
and, no, Netbeans won't provide those.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic