0

The setSize() method of a Frame only resizes the frame itself, not the canvas inside. Is there a way to resize a frame based on what size you want the interior to be?

I made this image to explain what I'm talking about: I used setSize(500,500);
http://oi44.tinypic.com/4uymur.jpg

I suppose I could count pixels, but that stuff is platform-dependent, and plus it's not elegant :P

Edited by kedxu

3
Contributors
5
Replies
19
Views
4 Years
Discussion Span
Last Post by kedxu
0

It depends on yout layout manager. You may need to call SetPreferredSize, setMinimumSize, setMaximumSize and/or setSize before calling pack. But is does work.

0

Is this the right way to approach it?

void createFrame(int[] location, int[] size){
        Frame f = new Frame();
        f.setLocation(location[0],location[1]);
        f.setPreferredSize(new Dimension(size[0],size[1]));
        f.setMinimumSize(new Dimension(size[0],size[1]));
        f.setMaximumSize(new Dimension(size[0],size[1]));
        f.setSize(size[0],size[1]);
        f.pack();
        f.setVisible(true);
}
1

Nevermind, found a way that works using your advice. Thanks for the help, guys!

Solution:

void createFrame(int[] location, int[] size) {
        JFrame f = new JFrame();
        f.setLocation(location[0],location[1]);
        f.getContentPane().setPreferredSize(new Dimension(size[0],size[1]));
        f.pack();
        f.setVisible(true);
}

Edited by kedxu

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.