Reputation: 4637
I have Added two JPanels into a JPanel
with GridBagLayout
. Now the issue is :
When the main panel loads it shows the upper panel bit above the actual place it should be and when data from db loads into the JTextfields
and JComboBox
then panel goes to its actual size.
sample code:
public class JPanelIssue extends JPanel {
public JPanelIssue() {
JPanel mainPanel = new JPanel(new GridBagLayout());
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
mainPanel.add(panel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.6, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
mainPanel.add(panel2, new GridBagConstraints(0, 1, 1, GridBagConstraints.REMAINDER, 1.0, 0.4,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
}
panel1
contains fields related to search criteria and panel2
contains JTable
dispalying reults.
Is there any problem of AWT event queue or any other problem?
Thanks in advance.
Upvotes: 0
Views: 90
Reputation: 109815
comment only
not reproducible from this code snipped, because you forgot to add something about JTextfields and JComboBox then panel goes to its actual size.
When the main panel loads it shows the upper panel bit above the actual place it should be and when data from db loads into the JTextfields and JComboBox then panel goes to its actual size.
GBC
is based on PreferredSize
came from JComponents
back to the contianer (by assuming that about JPanel
)
there are two ways
(proper)
set proper PreferredSize for JTextField and JComboBox too
(sizing hack)
override getPreferredSize
for JPanel
contains JTextField
and JComboBox
then all another parent(s) / containers should be notified without override any setSize
, setBounds
, setPreferredSize
, only by JFrame.pack()
Upvotes: 2