I am using GridBagLayout to align components. Actually, i have two buttons which i want to align like this:
Desired layout:
But the following code results in the following layout:
Resulted layout:
My code:
iconAdd = new ImageIcon(getClass().getResource("../images/add.png")); add = new JButton(iconAdd); add.setPreferredSize(new Dimension(130, 100)); add.setBorder(new LineBorder(Color.decode("#9b9999"), 1, true)); add.setCursor(Cursor.getPredefinedCursor(12)); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 5, 5); pane.add(add, gbc); iconSearch = new ImageIcon(getClass().getResource("../images/search.png")); search = new JButton(iconSearch); search.setCursor(Cursor.getPredefinedCursor(12)); search.setPreferredSize(new Dimension(130, 100)); search.setBorder(new LineBorder(Color.decode("#9b9999"), 1, true)); gbc.gridx++; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 5, 5); pane.add(search, gbc); Any help would be highly appreciated.


