0

I have a problem concerning layouts in Swing. I have got a BorderLayout and want to add a JProgressBar with multiple JLabels below in the NORTH section of this layout all aligned horizontal next to each other.

It should look something like this: enter image description here

I already tried various layouts like for example GroupLayout but I couldn't get it to work.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
LarsBauer
  • 1,539
  • 18
  • 23

1 Answers1

3

Consider using a second JPanel with a GridLayout...

setLayout(new BorderLayout());
add(new JProgressBar(), BorderLayout.NORTH);
JPanel panel = new GridLayout(1, 6);
panel.add(new JLabel("Step 1"));
panel.add(new JLabel("Step 2"));
panel.add(new JLabel("Step 3"));
panel.add(new JLabel("Step 4"));
panel.add(new JLabel("Step 5"));
panel.add(new JLabel("Step 6"));
add(panel, BorderLayout.CENTER);

As an example.

See How to Use GridLayout for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366