I want to make a layout with two componenents in a vertical row.
The first component is an instance of my own class, ImagePanel, that extends Panel and shows an image, and I want it to take up the exact space that it needs to show the entire image. The remaining space should then be filled by the other component (in this case another Panel with a GridLayout). See the picture.

In Android you can do this by using the weight property, but I have not been able to find anything like that in Java, and I can´t see that any of the standard layout managers in Java would be suitable for this.
I tried putting the ImagePanel in BorderLayout.NORTH and the other panel in BorderLayout.CERNTER, but the second panel was then overlapping the image, so that didn’t work.
I also thougth about using a GridLayout but the grid would not care about the size of the image, so I don’t think that would work either.
Any help is appreciated.
A BorderLayout should work, provided the image panel’s
getPreferredSize()returns the correct dimension (i.e. the dimension of the image it displays).Using a simple JLabel containing an ImageIcon and no text instead of your custom ImagePanel would do that for you.