Issue
Not sure if what I need is possible. I have a container (JPanel) that contains some internal elements. I was wondering if it is possible to force internal elements to fit into the container's size. I need them to be fully visible i.e., resize to fit inside the Panel's size and not cut some parts of the internal elements.
Scrolling is not an option.
Is this possible by using a Layout or something?
EDIT: Important clarification: The thing is that I do not have access to the internal elements neither to their properties so I would say that a Layoutmanager capable of resizing child elements to fit to its size is needed. I tested BorderLayout and GridBagLayout but the result is always the same, the internal elements are cut out.
Solution
It's for exactly that reason that LayoutManagers exist. All the LayoutManagers
work for simple containers directly, excluding GridBagLayout
which is to able to handle most complete GUIs directly.
For most complete GUI's you have some choices as follows:
- Look for a 3rd party layout such as MigLayout or here
- Use GridBagLayout
- Very easy way is use nested layout, where there is more than one
JPanel
and each has childJPanels
with the same or differentLayoutManager
- Or custom layout, should be hard..., but same as using
GridBagLayout
Answered By - mKorbel