Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > changing the color of JProgressBar

Reply
Thread Tools

changing the color of JProgressBar

 
 
Aryeh M. Friedman
Guest
Posts: n/a
 
      12-20-2007
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?
 
Reply With Quote
 
 
 
 
HightowerC
Guest
Posts: n/a
 
      12-20-2007
On Dec 20, 3:12 pm, "Aryeh M. Friedman" <(E-Mail Removed)>
wrote:
> 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
 
Reply With Quote
 
 
 
 
Aryeh M. Friedman
Guest
Posts: n/a
 
      12-21-2007
On Dec 20, 4:53 pm, HightowerC <(E-Mail Removed)> wrote:
> On Dec 20, 3:12 pm, "Aryeh M. Friedman" <(E-Mail Removed)>
> wrote:
>
> > 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
 
Reply With Quote
 
Qu0ll
Guest
Posts: n/a
 
      12-21-2007
"Aryeh M. Friedman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>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.

--
And loving it,

-Q
_________________________________________________
http://www.velocityreviews.com/forums/(E-Mail Removed)
(Replace the "SixFour" with numbers to email me)

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-21-2007
Aryeh M. Friedman wrote:
> On Dec 20, 4:53 pm, HightowerC <(E-Mail Removed)> wrote:
>> On Dec 20, 3:12 pm, "Aryeh M. Friedman" <(E-Mail Removed)>
>> wrote:
>>
>>> 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();
}
}

--
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
Color-coded JProgressBar? Sebastian Millies Java 0 01-12-2007 12:32 PM
JProgressbar look n feel FET Java 3 07-23-2004 03:41 AM
Still slightly clueless about this GUI thing...(JProgressBar never draws on a JDialog) Inertia_sublimation Java 5 01-03-2004 12:05 AM
Update of JProgressBar Cengiz Java 2 08-07-2003 10:07 AM



Advertisments