Controlling the size of a JProgressBar

I have a JDialog that has it's own Pane inside of it, inside the pane I have a JProgressBar and a JLabel, the idea is that I will have a progress bar and a label that will tell you what is currently running.

My problem is that even if I put a size on the JProgressBar, it is still huge, I want it to be a standard progressbar size, thin, not wide:

    public JProgressBar getTestProgress() {
        progress = new JProgressBar(0, 100);
        progress.setSize(250, 10);
        progress.setBackground(Color.darkGray);
        progress.setForeground(Color.LIGHT_GRAY);
        progress.setValue(0);
        progress.setVisible(true);
        progress.setStringPainted(true);
        progress.setString("Starting test run");

        return progress;
    }
   
    public JLabel progLabel(){
        progLabel = new JLabel("Running Tests:");
        return progLabel;
    }
   
    public JPanel progPane() {
        progPane = new JPanel();
        progPane.setLayout(new BorderLayout());
        progPane.add( getTestProgress(), BorderLayout.CENTER);
        progPane.add( progLabel(), BorderLayout.SOUTH);
        return progPane;
    }
   
    public JDialog getPopupBar() {
        progressPop = new JDialog();
        progressPop.setSize(300, 100);
        progressPop.setModal(true);
        progressPop.setUndecorated(true);
        progressPop.setResizable(false);
        progressPop.setLocation(jContentPane.getWidth() /2, jContentPane.getHeight() /2);
        progressPop.add(progPane());
        return progressPop;
    }


How can I make it thin?

Thanks!
LVL 2
k41d3nAsked:
Who is Participating?
 
zzynxConnect With a Mentor Software engineerCommented:
>> My problem is that even if I put a size on the JProgressBar, it is still huge

That's because of

>> progPane.add( getTestProgress(), BorderLayout.CENTER);

Make that

    progPane.add( getTestProgress(), BorderLayout.NORTH);

and it won't be that huge
0
 
zzynxSoftware engineerCommented:
Everything you put in the center of a Panel having the BorderLayout takes as much space as available

(Seems like reading http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html would be a good idea ;°)
0
 
k41d3nAuthor Commented:
;)

thanks!
0
 
zzynxSoftware engineerCommented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.