minimum size for a jframe


B

Brandon McCombs

I want to set a minimum size for a jframe but still allow it to be
resized. I found out that using setMinimumSize() does nothing because I
can still resize the window below the size I specify in that method. I
found where someone said to add a component listener and posted code to
do that on the forum's website. I tried that but the current width and
height of the window never change so it isn't doing anything.

LDAPFrame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
int width = getWidth();
int height = getHeight();

boolean resize = false;
System.out.println( width + " " + height);
if (width < MIN_WIDTH) {
resize = true;
width = MIN_WIDTH;
}
if (height < MIN_HEIGHT) {
resize = true;
height = MIN_HEIGHT;
}
if (resize)
setSize(new Dimension(width, height));
System.out.println( width + " " + height + getSize());
}
}
);

The first print out gives the initial size that I set the frame to but
so does the 2nd printout despite resizing the frame to even cause it to
print anything. And since the values are the same as the initial ones
they never go below the size of the initial size and therefore even when
I resize to the size where all the widgets are on top of each other the
frame isn't resized to the minimum.

any ideas?
 
Ad

Advertisements

A

Alex Hunsley

Brandon said:
I want to set a minimum size for a jframe but still allow it to be
resized. I found out that using setMinimumSize() does nothing because I
can still resize the window below the size I specify in that method.

Post a compilable self-contained example if you can!
 
Ad

Advertisements

A

Alex Hunsley

Brandon said:
I want to set a minimum size for a jframe but still allow it to be
resized. I found out that using setMinimumSize() does nothing because I
can still resize the window below the size I specify in that method. I

Post a self-contained compilable example...
Otherwise we have problem such as having no idea what type your
LDAPFrame is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top