Finding the Size of a Window
I have written code to display images inside a JFrame. I have code that will resize the image, but I would like to link this resizing to the user resizing the window . Is there any way to monitor the size of the window. I have tried adding adding a MouseMotionListener to my JFrame, but it only sees when I drag inside the picture not on the border of the window.
Thanks in advance.
[402 byte] By [
thistleS] at [2007-9-26 1:14:04]

you could also write your own LayoutManager
myFrame.getContentPane().setLayout(new LayoutManager(){
private Dimension origin = new Dimension(0, 0);
//
public void layoutContainer(Container c) {
Rectangle b = c.getBounds();
Insets frameInsets = c.getInsets();
int inset = frameInsets.bottom;
int width = b.width-2*inset;
int height = b.height-inset-frameInsets.top;
//
//assuming the method you defined to resize your image is
//called "resizeImage(width,height)":
resizeImage(width,height):
//
//... and assuming image is displayed on a Component called myImagePane:
myImagePane.setBounds(inset, frameInsets.top, width, height);
// and do setBounds on any other components you want in the frame here...
}
public Dimension preferredLayoutSize(Container c) {return origin; }
public Dimension minimumLayoutSize(Container c) {return origin; }
public void addLayoutComponent(String s, Component c) {}
public void removeLayoutComponent(Component c) {}
}