1

I've currently created the GridLayout: It's got 4 columns, first two are progress bars, the other two start/stop buttons. How can I get the last two buttons to be next to eachother?

How I want it:
PROGRESS BAR
PROGRESS BAR
START STOP

How it is:
PROGRESS BAR
PROGRESS BAR
START
STOP

Even if I change the layout to: panel.setLayout(new GridLayout(3, 2, 3, 3)); It doesn't work, can anyone help me?

John Smith
  • 39
  • 1
  • 8

1 Answers1

3

Just put the two JProgressBars to a JPanel say centerPanel with BridLayout(0, 1, 5, 5).

And put the 2 JButtons START and STOP to another JPanel say buttonPanel with Layout i.e. FlowLayout(FlowLayout.LEFT, 5, 5) (This will align the JButton START with the left side of the JProgressBars, though if you want the JButtons to come somewhere in the middle of the same, then simply don't use setLayout(FlowLayout.LEFT, 5, 5). The default Layout for the JPanel will do).

Now add centerPanel to the JFrame using

frameReference.add(centerPanel, BorderLayout.CENTER) 

and add buttonPanel using

frameReference.add(buttonPanel, BorderLayout.PAGE_END)

That will do :-)

EDIT 1 :

use a Border for this thingy. Like

centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK))

That will create a Box around the centerPanel. Please have a look at this answer, though I am using TitledBorder in this example.

Community
  • 1
  • 1
nIcE cOw
  • 24,468
  • 7
  • 50
  • 143
  • Thanks :) I had to edit it a little, but I got it working. Is it possible to group everything? For example have a box surrounding the two progress bars and buttons so it's separated from everything else? – John Smith Sep 01 '13 at 17:26