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

Auto Maximise GUI

 
Zahid, Butt
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have the following code :
import java.awt.*;
public class TestFlow extends Frame {
public static void main(String args[]) {
Panel p = new Panel();
Button b = new Button("NORTH");
Button b1 = new Button("SOUTH");
Button b2 = new Button("CENTER");
TestFlow t = new TestFlow();
t.setSize(450,450);
t.setVisible(true);
t.add(p);
p.add(b);
p.add(b1);
p.add(b2);
}
}
How do I maximise the panel to be the size of my Monitor screen ?

Thanks in advance.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi you can use this
Dimenstion d = getToolkit().getDefaultScreenSize();
i can't remember the exact method but something like this and then set it to setSize(d)
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last I heard, there was no way to programatically maximize a window without using JNI. The best you can do is set its size equal to the size of your screen (which isn't really the same as miximizing it). There are some resources on the internet that show how you can do this using JNI, if you're interested.
 
Zahid, Butt
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Bodie, could you please give me URL's that further explain your comments.
Thanks.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't provide any way to maximize a JFrame. On a Windows platform, this can only be achieved via the use of native code. This requires using JNI to integrate native code with your Java program. You can find a JNI tutorial here. I used to have a link to some C code that handled the maximization of the window, but I can't find it now that I need it. Sorry.
HTH
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic