Reputation:
so I'm working on a project that requires me to open images, scale the window to fit the image, and have the window scale back down when the window is removed.
I have my Window broken into a BorderLayout container, which then holds a FlowLayout container, which finally holds my JLabel with the icon set to my desired image. There are some other containers but they shouldn't matter.
I'm using .pack to resize the window and then setMiniumSize to whatever pack sets the size to.
The problem is I don't think I'm properly removing the image from the Label so when I call pack again the window remains the same size.
label.setIcon(null);
if (theImage != null) {
myRawImage = theImage;
label.setIcon(new ImageIcon(myRawImage));
}
myWindow.pack();
myWindow.setMinimumSize(myWindow.getSize());
This code properly scales the window up but if I change theImage to null after having it as something else the window stays the same size.
Any help would be greatly appreciated.
Upvotes: 0
Views: 27
Reputation: 324197
There is no need for the setMinimumSize() method. Let the layout manager do its job.
Just do a frame.pack()
to resize the frame.
Upvotes: 3