Skip to main content

Jpanel Pack

1 reply [Last post]
junaam
Offline
Joined: 2009-10-05
Points: 0

Hi
I devloping a program in java swing that need to create field dynamcly.
i Create a JPanel that take the name and number of fields you need it call for anther JPanel that crate all the fields
and the display them and anlyzi the data.
when this was the only form i used a JFrame
and for the dynamic Fields i used the:
pack() command .
but i need a lot more JFrame that related one to anthe.
so I used a JDesktoppane and JIntenalFrame
But then I need to use a JPanel but there is no Pack command for JPanel
basically I need the replacement of the Pack command from JFrame in JPanel.
someone have an idea?
Thank you
Junaam

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rameye
Offline
Joined: 2011-06-09
Points: 0

JFrame descends from Window. JPanel does not. That is why you cannot pack() a JPanel.

Attach suitable layout managers to your JPanel objects. There are many to choose from and each has it's own way of laying things out.

JFrame.pack() resizes the JFrame, so that all the JPanel subcomponents have room to show. If you have attached layout managers to these JPanel objects before building them, when JFrame.pack() is invoked the JPanel objects will be nicely sized to show their internal components nicely arranged.

So I am thinking that "replacement of the Pack command from JFrame in JPanel" can be achieved by proper use of a layout manager.

Study and play around with the layout managers, the time you spend will be well rewarded later.