Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

changing the color of JProgressBar

Thread view: 
Aryeh M. Friedman - 20 Dec 2007 21:12 GMT
I have a JProgressBar that I want to be green if the underlaying
process has no errors and red if it does.   I can't seem to find a way
of setting the color of the bar in the raw JProgressBar class... ideas?
HightowerC - 20 Dec 2007 21:53 GMT
> I have a JProgressBar that I want to be green if the underlaying
> process has no errors and red if it does.   I can't seem to find a way
> of setting the color of the bar in the raw JProgressBar class... ideas?

Try JProgressBar.setForeground(Color c)

HightowerC
Aryeh M. Friedman - 21 Dec 2007 01:45 GMT
> > I have a JProgressBar that I want to be green if the underlaying
> > process has no errors and red if it does.   I can't seem to find a way
> > of setting the color of the bar in the raw JProgressBar class... ideas?
>
> Try JProgressBar.setForeground(Color c)

No effect
Eric Sosman - 21 Dec 2007 18:40 GMT
>>> I have a JProgressBar that I want to be green if the underlaying
>>> process has no errors and red if it does.   I can't seem to find a way
>>> of setting the color of the bar in the raw JProgressBar class... ideas?
>> Try JProgressBar.setForeground(Color c)
>
> No effect

    Works for me.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Bar extends JFrame {

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Bar().setVisible(true);
            }
        });
    }

    private final JProgressBar pbar = new JProgressBar(0, 10);
    private final JButton butt = new JButton("Click Me");

    private Bar() {
        butt.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                BoundedRangeModel model = pbar.getModel();
                int value = model.getValue();
                if (value == 3)
                    pbar.setForeground(Color.GREEN);
                else if (value == 7)
                    pbar.setForeground(Color.RED);
                model.setValue(value + 1);
            }
        });

        setLayout(new FlowLayout());
        add(pbar);
        add(butt);
        pack();
    }
}

Signature

Eric.Sosman@sun.com

Qu0ll - 21 Dec 2007 08:58 GMT
>I have a JProgressBar that I want to be green if the underlaying
> process has no errors and red if it does.   I can't seem to find a way
> of setting the color of the bar in the raw JProgressBar class... ideas?

I think you'll find the colour is controlled by the prevailing PLAF.

Signature

And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.