how to tell source of resizing
Hi all, I want to implement the following policy:
1) if Java runtime resizes the window to fit GUI components in there, I want it to stay the size it is or larger (not shrink).
2) if the GUI is resized by the user, allow the GUI to get larger or smaller depending on how the user resizes it.
I can implement #1 by adding a componentListener on resize. But, i can't figure out how to tell the difference between user resizing the window and the GUI doing it on its own.
If I don't implement this at all, the GUI is constantly resizing as the component contents (text fields, tables etc) change content. If I have #1 and not #2, the window can get larger but never smaller.
Here is the sample code of how I implement #1 above:
public void componentResized(ComponentEvent e)
{
Component c = e.getComponent();
System.out.println("Resize event x=" + c.getSize().getWidth() + "y=" +
c.getSize().getHeight() + " source=" +e.getSource().toString());
int last_width = (int)my_preferred_size.getWidth();
int last_height = (int)my_preferred_size.getHeight();
int this_width = c.getWidth();
int this_height = c.getHeight();
if (this_width < last_width) {
this_width = last_width;
}
if (this_height < last_height) {
this_height = last_height;
}
my_preferred_size = new Dimension(this_width,this_height);
c.setPreferredSize(my_preferred_size);
}

