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);

}

[1484 byte] By [Developer_Named_Aarona] at [2007-11-27 10:36:31]
# 1

I don't understand your question. The "Java runtime" does not resize the frame on its own.

If you add or remove components from a frame the size of the frame does not change, unless of course you invoke the pack() or setSize() method. So if you want the size of the frame to stay the same then just don't use either of the above method.

camickra at 2007-7-28 18:41:46 > top of Java-index,Desktop,Core GUI APIs...
# 2

You are right, I am calling frame.pack. I was a little confused about what that did. I removed it from some places and now the window only sizes when I want it to...I have other problems but I'll save that for another thread.

Thanks again.

Developer_Named_Aarona at 2007-7-28 18:41:46 > top of Java-index,Desktop,Core GUI APIs...