I am having the following swing component. Please see the image. Here the label and the combobox and label and the textfield are not properly aligned. Any idea what is causing this issue?
I am using the GridBagLayout in a panel. Then adding the components such as label and combobox and textfield to the panel.
Following is the code i used.
srchCategoryLbl = new JLabel("Category");
categoryCmb = new JComboBox<>();
categoryCmb.setPreferredSize(dimensionTxt);
categoryCmb.setBounds(0, 0, 0, 0);
srchProductCodeLbl = new JLabel("Product Code");
productCodeTxt = new JTextField();
productCodeTxt.setPreferredSize(dimensionTxt);
srchProductDescLbl = new JLabel("Product Desc");
productDescTxt = new JTextField();
productDescTxt.setPreferredSize(dimensionTxt);
searchBtn = new JButton("Search");
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
searchPanel.add(srchCategoryLbl, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
searchPanel.add(categoryCmb, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
searchPanel.add(srchProductCodeLbl, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
searchPanel.add(productCodeTxt, gbc);
gbc.gridx = 2;
gbc.gridy = 0;
searchPanel.add(srchProductDescLbl, gbc);
gbc.gridx = 2;
gbc.gridy = 1;
searchPanel.add(productDescTxt, gbc);
gbc.gridx = 3;
gbc.gridy = 1;
searchPanel.add(searchBtn, gbc);