[SOLVED] Change Hight of the PogressBar

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

[SOLVED] Change Hight of the PogressBar

Postby GGK » Tue Aug 05, 2014 10:55 am

Hi,

is there a way to change the default hight of the progressbar.

changing the width is possible...
Code: Select all
setPreferredProgressWidth();


Thanks
GGK
GGK
 
Posts: 7
Joined: Tue Aug 05, 2014 8:48 am

Re: Change Hight of the PogressBar

Postby frizinator » Wed Aug 06, 2014 12:23 am

Yes, this is done by using:
Code: Select all
yourProgressBar.setPrefferedSize(new Dimension(int h, int w)


Where int h is the height in an integer specification, as well as w is the width.
frizinator
 
Posts: 12
Joined: Fri Dec 07, 2012 8:14 am

Re: Change Hight of the PogressBar

Postby GGK » Wed Aug 06, 2014 9:12 am

Thanks,

but it seems to me that there is no possibility to set progressbar like 5px, isn't it?

I use that code:
Code: Select all
      progressBar = new JProgressBar();
      WebProgressBarUI wGui = new WebProgressBarUI();
      wGui.setBgBottom(SystemColor.inactiveCaptionBorder);
      wGui.setBgTop(SystemColor.inactiveCaptionBorder);
      progressBar.setPreferredSize(new Dimension(150,10));
      progressBar.setUI(wGui);


GGK
GGK
 
Posts: 7
Joined: Tue Aug 05, 2014 8:48 am

Re: Change Hight of the PogressBar

Postby mgarin » Wed Aug 06, 2014 1:19 pm

Well, you can actually set the height of the progress bar to 5px, but you won't be able to see the progress by default unless you change the progress bar styling - for example nullify its shade width.

Here is an example:
Code: Select all
public class Test
{
    public static void main ( final String[] args )
    {
        WebLookAndFeel.install ();

        final JProgressBar jpb = new JProgressBar ( 0, 100 );
        jpb.setValue ( 75 );
        jpb.setPreferredSize ( new Dimension ( 150, 5 ) );

        final WebProgressBar wpb = new WebProgressBar ( 0, 100 );
        wpb.setValue ( 75 );
        wpb.setPreferredHeight ( 5 );
        wpb.setShadeWidth ( 0 );

        TestFrame.show ( 5, false, 20, jpb, wpb );
    }
}


As you can see - WebProgressBar has setPreferredHeight method which you can use directly. JProgressBar doesn't have one so you will need to use setPreferredSize.

I have also set shade width for 2nd progress bar so you can actually see the progress on it. Still, it is not the best view - I will be improving components to look properly in small sizes later.

Also, I strongly recommend you to either install WebLaF as your L&F (like in the example above) or use Web-components instead of J-components (WebProgressBar instead of JProgressBar in this case) since they have Web-UIs pre-installed and you won't need to set it manually. That way you will also avoid getting some other possible issues.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Change Hight of the PogressBar

Postby GGK » Wed Aug 06, 2014 4:58 pm

Thanks for the hints.
I think, the problem is my standard LayoutManager...I use the Mig Layout Manager...

Code: Select all
import java.awt.EventQueue;
import java.awt.SystemColor;

import javax.swing.JFrame;

import com.alee.laf.progressbar.WebProgressBar;
import net.miginfocom.swing.MigLayout;

public class TestWebJProgressBar extends JFrame {

   public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
         public void run() {
            try {
               TestWebJProgressBar frame = new TestWebJProgressBar();
               frame.setVisible(true);
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
      });
   }

   
   public TestWebJProgressBar() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 450, 300);
      getContentPane().setLayout(new MigLayout("", "[]", "[][5px:5px:5.00px]"));
      
   
      
      WebProgressBar wpb = new WebProgressBar ( 0, 100 );
        wpb.setValue ( 75 );
        wpb.setPreferredHeight (3 );
        wpb.setShadeWidth ( 0 );
        getContentPane().add(wpb, "cell 0 1");
       
   }
}
GGK
 
Posts: 7
Joined: Tue Aug 05, 2014 8:48 am

Re: Change Hight of the PogressBar

Postby GGK » Wed Aug 06, 2014 5:02 pm

solved it:
Code: Select all
getContentPane().add(wpb, "cell 0 1,height 5!")


Thanks supporting me!

GGK
GGK
 
Posts: 7
Joined: Tue Aug 05, 2014 8:48 am

Re: Change Hight of the PogressBar

Postby mgarin » Wed Aug 06, 2014 5:31 pm

Unfortunately I didn't work a lot with Mig Layout so can't help with it.
But anyway, glad you solved the problem :)
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron