[Swing-Progress Bar] Can't resize progress bar
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [Swing-Progress Bar] Can't resize progress bar

  1. #1
    Join Date
    Mar 2010
    Posts
    7

    [Swing-Progress Bar] Can't resize progress bar

    Hello,

    I can't resize my progress bar. I can change the size only horizontally, not vertical.

    JPanel content = new JPanel (new BorderLayout());
    content.setLayout(new BorderLayout());
    content.add(areaScrollPane, BorderLayout.PAGE_START);
    content.setPreferredSize(new Dimension(500, 455));

    pb = new JProgressBar(0, 100);
    pb.setStringPainted(true);
    pb.setOrientation(SwingConstants.VERTICAL);
    pb.setValue(10);
    pb.setMaximumSize(new Dimension(130,140));

    content.add(pb, BorderLayout.WEST);

  2. #2
    Join Date
    Mar 2010
    Posts
    7

    Re: [Swing-Progress Bar] Can't resize progress bar

    Do you guys have any idea what is wrong here?

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Swing-Progress Bar] Can't resize progress bar

    Your code only shows you setting the maximum size - how are you trying to change the height?

    Programming is an explanatory activity...
    R. Harper
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Mar 2010
    Posts
    7

    Re: [Swing-Progress Bar] Can't resize progress bar

    So... how should I? I don't have the code now but I have tried few things already. I may missing something so I decided to post my problem here.
    Could you please tell me how to set height and width of JProgressbar?

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Swing-Progress Bar] Can't resize progress bar

    It should work just like every other Component - with setPreferredSize(..).

    If that isn't working, there's probably something odd with the layout, but it looks OK on what you posted.

    All truths are easy to understand once they are discovered; the point is to discover them...
    G. Galilie
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    Mar 2010
    Posts
    7

    Re: [Swing-Progress Bar] Can't resize progress bar

    Still, it changes size only vertically. Here is more code:

    JPanel content = new JPanel (new BorderLayout());
    content.setLayout(new BorderLayout());
    content.add(areaScrollPane, BorderLayout.PAGE_START);
    content.setPreferredSize(new Dimension(500, 455));

    JProgressBar pb;

    pb = new JProgressBar(0, 100);
    pb.setStringPainted(true);
    pb.setOrientation(SwingConstants.VERTICAL);
    pb.setValue(10);
    pb.setPreferredSize(new Dimension(100,50));

    /*
    Dimension prefSize = pb.getPreferredSize();
    prefSize.height = 50;//some width
    pb.setPreferredSize(prefSize);
    */

    content.add(pb, BorderLayout.WEST);



    // ********** MENU ***************
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = menuBar.add(new JMenu(text.getString("order")));
    fileMenu.setMnemonic('F');
    fileMenu.add(_coffebean1);
    fileMenu.add(_coffebean2);
    fileMenu.add(_coffebean3);
    fileMenu.add(_coffebean4);
    fileMenu.add(_cyrkonia);
    fileMenu.addSeparator();
    fileMenu.add(_exitAction);

    JMenu runMenu = menuBar.add(new JMenu(text.getString("run")));
    JMenu reportMenu = menuBar.add(new JMenu(text.getString("report")));

    JMenu optionsMenu = menuBar.add(new JMenu(text.getString("options")));
    optionsMenu.add(createMenuColors(text.getString("background")));

    setContentPane(content);
    setJMenuBar(menuBar);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle(text.getString("title"));
    pack();
    setLocationRelativeTo(null);
    setVisible(true);

  7. #7
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Swing-Progress Bar] Can't resize progress bar

    Post 1:
    I can't resize my progress bar. I can change the size only horizontally, not vertical.
    Post 3:
    Still, it changes size only vertically.
    If you could make up your mind whether it's the horizontal or vertical size you want to change, it would be easier to help.

    Running the code you posted gives me a vertical progress bar the full height of the frame and whatever width is specified. The height depends on the height of the frame because that's how a BorderLayout WEST area works when there's no NORTH or SOUTH components - see BorderLayout.

    If you were clearer about what you're trying to achieve, it would be easier to suggest something.

    Precise language is not the problem. Clear language is the problem...
    R. Feynman
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  8. #8
    Join Date
    Mar 2010
    Posts
    7

    Re: [Swing-Progress Bar] Can't resize progress bar

    Quote Originally Posted by dlorde View Post
    Post 1:

    If you were clearer about what you're trying to achieve, it would be easier to suggest something.

    Sorry, my mistake. I can't change vertical size of button, but I can change its width. I have not copied full code before, here it is:

    // ******* TEXT AREA 1 - STATUS *********
    textArea_status.append (text.getString("action_run"));
    textArea_status.setFont(new Font("Serif", Font.CENTER_BASELINE, 11));
    textArea_status.setLineWrap(true);
    textArea_status.setWrapStyleWord(true);
    textArea_status.setEditable(false);

    JScrollPane areaScrollPane = new JScrollPane(textArea_status);
    //areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    areaScrollPane.setPreferredSize(new Dimension(50, 50));

    areaScrollPane.setBorder(
    BorderFactory.createCompoundBorder(
    BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder(text.getString("lastac")),
    BorderFactory.createEmptyBorder(3,3,3,3)),
    areaScrollPane.getBorder()));




    JPanel content = new JPanel (new BorderLayout());
    content.setLayout(new BorderLayout());
    content.add(areaScrollPane, BorderLayout.PAGE_START);
    content.setPreferredSize(new Dimension(500, 455));

    JProgressBar pb;

    pb = new JProgressBar(0, 100);
    pb.setStringPainted(true);
    pb.setOrientation(SwingConstants.VERTICAL);
    pb.setValue(10);
    pb.setPreferredSize(new Dimension(100,50));

    /*
    Dimension prefSize = pb.getPreferredSize();
    prefSize.height = 50;//some width
    pb.setPreferredSize(prefSize);
    */

    content.add(pb, BorderLayout.WEST);



    // ********** MENU ***************
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = menuBar.add(new JMenu(text.getString("order")));
    fileMenu.setMnemonic('F');
    fileMenu.add(_coffebean1);
    fileMenu.add(_coffebean2);
    fileMenu.add(_coffebean3);
    fileMenu.add(_coffebean4);
    fileMenu.add(_cyrkonia);
    fileMenu.addSeparator();
    fileMenu.add(_exitAction);

    JMenu runMenu = menuBar.add(new JMenu(text.getString("run")));
    JMenu reportMenu = menuBar.add(new JMenu(text.getString("report")));

    JMenu optionsMenu = menuBar.add(new JMenu(text.getString("options")));
    optionsMenu.add(createMenuColors(text.getString("background")));

    setContentPane(content);
    setJMenuBar(menuBar);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle(text.getString("title"));
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
    }

  9. #9
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Swing-Progress Bar] Can't resize progress bar

    Quote Originally Posted by Grabar View Post
    Sorry, my mistake. I can't change vertical size of button, but I can change its width.
    button? the what, now?

    The first step towards wisdom is calling things by their right names...
    Chinese proverb
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  10. #10
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Swing-Progress Bar] Can't resize progress bar

    Like I said before, BorderLayout.WEST fills the height of the panel between the NORTH and SOUTH (or PAGE_START & PAGE_END) areas, and takes up it's preferred width if allowed by the CENTER area.

    If you want to change the height of the progress bar, you need to use an appropriate layout manager. For example, you could put the progress bar into its own panel using BorderLayout.SOUTH and put that panel into your content pane in BorderLayout.WEST. BorderLayout.SOUTH occupies the bottom width of the panel and extend upwards to its preferred height if allowed by the CENTER area.

    Teachers open the door, but you must enter by yourself...
    chinese proverb.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  11. #11
    Join Date
    Mar 2010
    Posts
    7

    Re: [Swing-Progress Bar] Can't resize progress bar

    Hehe, it is not my day today Anyway thanks, I will try it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center