I have a JFrame
with a single JPanel
inside. The panel displays images that are received from the network at runtime. These images are usually big, but can have any size. Considering this and given that I might add a menu bar to the frame in the future, I'd like to do the following:
- For each received image, the panel resizes to its exact size.
- If the image (and hence the resized panel) exceeds a certain maximum value in width or height (e.g.: the screen size - 100px), then the frame should resize to the maximum allowed value and enable scrollbars.
- Otherwise, the frame should adjust its size to display the entire panel without any padding. So the frame size is the content panel size plus the borders and the title bar (and the menu bar if I finally add it).
Is there a way to do this? If not, what would be the best alternative?
Thanks in advance
EDIT:
The problem, to summarize, is how to resize the parent frame to adjust to its child content panel. This is the opposite of what most people do (resize panel to fit frame).
For point #3, I already have the content panel dimension, so the problem is reduced to calc the size of the frame's frame (top title bar height, borders width). With that, I could resize the frame to a size such as the content pane fits exactly inside.