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?
Just put the two JProgressBar
s to a JPanel say centerPanel
with BridLayout(0, 1, 5, 5)
.
And put the 2 JButton
s START and STOP
to another JPanel say buttonPanel
with Layout ie FlowLayout(FlowLayout.LEFT, 5, 5)
(This will align the JButton
START with the left side of the JProgressBar
s, though if you want the JButton
s to come somewhere in the middle of the same, then simply don't use . The default Layout for the setLayout(FlowLayout.LEFT, 5, 5)
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 :-)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.