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?
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?