I want to resize an image inside a JGoodies form layout according to the size the cell has, i.e. so that the image fits perfectly in the cell. If I understand correctly, there is no real component for the cell, the size is known only implicitly by the layout manager, right? Any ideas?
Asked
Active
Viewed 294 times
0
-
You are right, there is nor real cell component. And you shouldn't resize the the image inside a cell to fit the cell. This is what the layout manager is for. You have to tell the image or its container that it should expand/grow/fill to its cells size. I unfortunately don't know the jGoodies FormLayout that well to give you an example. – Sam Feb 04 '14 at 14:33
-
1That's no problem for a one time operation, you are right. But I want to be able to resize the image after it has been rendered by listening to resize events on the window. That means, if the user changes the window size, the layout manager repaints the layout and the cell changes size, but the image is already rendered and doesn't dynamically change the size. That's why I need to do this manually and need the exact target size. – jan Feb 04 '14 at 14:41
-
1hmmm ... might be possible to [put the image/panel into a scrollPane](http://stackoverflow.com/a/12769969/203657), then you could tweak both the sizing hints and the image scaling on the higher level of abstraction of a Scrollable. – kleopatra Feb 04 '14 at 15:01
1 Answers
0
As suggested by kleopatra I found this solution: The image is put inside a scrollPane and I get the viewable size of the cell by
javax.swing.JComponent.getVisibleRect().getWidth();
where the JPanel is a JComponent... I can't paste more code directly, as we use other frameworks that wrap Swing and I didn't test that directly, sorry. If somebody else has this problem and uses this solution please add low level Swing code, thanks.
Thanks for your suggestions!

jan
- 2,741
- 4
- 35
- 56
-
A caveat with that approach is that in live resizing the scrollbars can become a problem, because they flicker. I ended up setting to hide them always. – jan Feb 11 '14 at 09:14