Skip to main content
gamedev.net
🔒 Locked

[java] Setting size on Frame?

Started by bilsa 6 replies 1.3k views
Original Post
bilsa
bilsa
Hey guys! Lets say I have a frame: Frame frame1 = new Frame(); //or whatever... JPanel panel = new JPanel(); panel.setSize(100,100); frame1.setSize(panel.getWidth(),panel.getHeight()); //That will create the same size but not counting that //I want the actual "content" area to be of the size I pass. //the Frame borders will take up some size of the dimension //I set... So, could someone tell me how to set the size the way I want with a normal Frame? thank you! [edited by - bilsa on May 11, 2004 5:16:42 PM]
bilsa
bilsa
heh... Just used pack()
ManiacMac
ManiacMac
Just go something like

JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(100, 100));

Then add it to the Frame. Dont set the size on the frame. AFter using setPreferredSize() and pack();, it should work like you want it to. That should be want you want I hope.
zoerb
zoerb
use
Insets insetsName = frame1.getInsets()
then resize based on the size of each inset,
insetsName.bottom
insetsName.left
insetsName.right
insetsName.top
Strife
Strife
pack has a tendency to not work the way you really want it. That''s really the biggest downfall to Swing, IMO. Its resizing functions just don''t work. Layout doesn''t work very well unless you play with it constantly.

Or, it could be that I''m just dumb.

It just seems that it''s really finnicky.
HellCreator
HellCreator
Hi

I have found for me
setBounds(xstart,ystart,width,height)
and it is solve for me all trubles with JFrame and JPanel
and with window sizing and positioning on screen or on frame

pack() just make space between components smaller
but not keep the sequense of them I tryed
in some cases pack() - powerfull

Can''t be root?Reboot!
mount -r /home/hell
Can't be root?Reboot!mount -r /home/hell
zoggo
zoggo
You can only use getInsets once the frame has a peer. This is why is generally easier to use layout managers - they handle layouts whenever the frame asks for it which will be just before it gets shown but after it has gained a peer. If you try and do this from else where you are asking for pain.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.