Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4771
  • Last Modified:

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!
0
k41d3n
Asked:
k41d3n
  • 3
1 Solution
 
zzynxSoftware 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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now