I tried to vertically align JButton
, but I had a problem with stretching. After grumbling, I found this to work:
JPanel jpTop = new JPanel(new BorderLayout()); jbStop = new JButton("Cancel"); JPanel extraPanel = new JPanel(); extraPanel.setLayout(new BoxLayout(extraPanel, BoxLayout.X_AXIS)); extraPanel.setAlignmentY(Component.CENTER_ALIGNMENT); extraPanel.add(jbStop); jpTop .add(extraPanel, BorderLayout.EAST);
Of course, this works for JLabel as well.
Vit bernatik
source share