I want to have a JLabel and a JButton next to each other, in the next row an other Jlaben and in the next row a JButton that is in the center.
The leftPanel is 350 wide.
The first JButton has an ImageIcon and that should be in the right top corner, that image is 25x25.
This code returns a panel to get then shown
JPanel leftPanel = JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
JLabel userLabel = new JLabel();
userLabel.setPreferredSize(new Dimension(170, 25));
userLabel.setMaximumSize(new Dimension(170, 25));
leftPanel.add(userLabel);
// class that creats a JButton with an ImageIcon and removes border
JButton updateButton = DefaultLayouts.imageButton(new ImageIcon("src/ressources/images/icons/update.png"));
updateButton.setPreferredSize(new Dimension(170, 25));
updateButton.setMaximumSize(new Dimension(170, 25));
leftPanel.add(updateButton);
timeStampLabel.setPreferredSize(new Dimension(350, 25));
timeStampLabel.setMaximumSize(new Dimension(350, 25));
leftPanel.add(timeStampLabel);
unlockButton = DefaultLayouts.imageButton(new ImageIcon("src/ressources/images/icons/unlock.png"));
unlockButton.setPreferredSize(new Dimension(350, 25));
unlockButton.setMaximumSize(new Dimension(350, 25));
leftPanel.add(unlockButton);
panel.add(leftPanel();
Now it's just in the center and I don't know what to do with the blue button. image
Updated Code:
JPanel panel = DefaultLayouts.panel();
panel.setLayout(new GridLayout(0, 2));
JPanel leftPanel = DefaultLayouts.marginPanel(0, 10, 0, 10);
leftPanel.setLayout(new GridBagLayout());
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
leftPanel.add(userLabel, gridBagConstraints);
JButton updateButton = DefaultLayouts.imageButton(new ImageIcon("src/ressources/images/icons/update.png"));
gridBagConstraints.gridwidth = 1;
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
leftPanel.add(updateButton, gridBagConstraints);
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
leftPanel.add(timeStampLabel, gridBagConstraints);
unlockButton = DefaultLayouts.imageButton(new ImageIcon("src/ressources/images/icons/unlock.png"));
gridBagConstraints.gridwidth = 3;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
leftPanel.add(unlockButton, gridBagConstraints);
panel.add(leftPanel);