Reputation: 356
JLabel titleLabel = new JLabel(title, SwingConstants.CENTER);
titleLabel.setForeground(Color.DARK_GRAY);
titleLabel.setFont(new Font("Comic Sans MS", Font.PLAIN, 15));
add(titleLabel, BorderLayout.PAGE_START);
JLabel descLabel = new JLabel("<html>description");
descLabel.setForeground(Color.GRAY);
descLabel.setFont(new Font("Comic Sans MS", Font.PLAIN, 13));
add(descLabel, BorderLayout.PAGE_START);
JLabel picLabel = new JLabel(new ImageIcon(Home.class.getResource("/icon/img.jpg")));
picLabel.setIconTextGap(-310);
picLabel.setOpaque(true);
picLabel.setLayout(null);
add(picLabel);
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(new LineBorder(Color.BLACK, 1, true));
JButton btnDetails = new JButton("Dettagli");
JButton btnDetails2 = new JButton("Modifica");
buttonPanel.add(btnDetails);
buttonPanel.add(btnDetails2);
add(buttonPanel);
I want to change the dimension of the panel (see the image) and align it with the image.
Any suggestion ?
Upvotes: 0
Views: 53
Reputation: 13858
Change the layout of your main panel to use BorderLayout
.
Then add the picLabel
to be add(picLabel, BorderLayout.CENTER)
and your buttonPanel as add(buttonPanel, BorderLayout.SOUTH)
and you should get better layout.
Packing the dialog / frame will also help.
You cannot add two labels to the same position in a BorderLayout. Your label descLabel
will replace your titleLabel
You could do that like the buttons: Create another panel, add both labels vertically and add that to your main panel with BorderLayout.NORTH
(or PAGE_START)
Upvotes: 3