Just a quick question here. I have a program in which I need to create a number of JPanels, which will then each contain some objects (usually JLabels).
There are a few operations that I have to do each time i create a new JPanel, and I’m wondering if the order in which I do them has any bearing, or if there is a standard practice.
The operations I do are the following:
Declare the JPanel: JPanel panel = new JPanel(…)
Declare the JLabel: JLabel laberl = new JLabel…
Add the JPanel to some other content pane: frame.getContentPane().add(panel)
Set the bounds of the JPanel: panel.setBounds(…)
Add the JLabel to the JPanel: panel.add(label)
Have a method createPanel() that returns the panel with all its children added.
And then
The order of constructing and adding items isn’t important, except that when you add children, you should
addthem in the order you want them in the panel.