Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to create transparent JProgress Bar or customize JProgress Bar?

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking How to create transparent JProgress Bar or customize JProgress Bar?

    can anyone give me example codes on how to create transparent JProgress Bar or customize JProgress Bar


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: JProgressBar

    Here is a way to make a transparent popup menu. You can modify this code to work with other Swing components such as the JProgress bar.

    import javax.swing.*;
    import java.awt.*;
     
    class TransparentPopupMenu extends JPopupMenu {
         public TransparentPopupMenu() { 
              super();
              setOpaque(false); 
         } 
    }
     
    class TransparentMenuItem extends JMenuItem{
         public TransparentMenuItem(String text) { 
              super(text);
              setOpaque(false); 
         } 
     
         public void paint(Graphics g) { 
              Graphics2D g2 = (Graphics2D) g.create(); 
              g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
              super.paint(g2); 
              g2.dispose(); 
         } 
    }
    The transparency level is set here:

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, [B]0.5f[/B]));


    0.0f
    means 100% transparent (you will not see it)
    0.5f means 50% transparent
    1.0f means 0% transparent (Not transparent at all)

    Also look here:

    Hacking Swing: Translucent Windows | O'Reilly Media
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers