We help IT Professionals succeed at work.

Can i set the color for the scrollbar of  JScrollPane

javamahesh
javamahesh asked
on
hello can i set the color for the scroll bar of the JscrollPane
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
sp.getVerticalSCrollbar().setForeground(Color.red);

Commented:
scrollPane.getVerticalScrollBar().setBackground(Color.red);
scrollPane.getHorizontalScrollBar().setBackground(Color.green);

Commented:
>> sp.getVerticalSCrollbar().setForeground(Color.red);

setForeground() doesn't seem to work at all!
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
What changing the background/foreground colour actually does depends partly on the particular L&F in use.
It wasn't actually specified which part of the scroll bar they want to change the colour of so I provided details on how to access the scroll bar component and change a colour attribute. I thought the means to change the foreground colour was pretty obvious.

Author

Commented:
i tried Background setting, but the barcolor has not been set,and with Foreground also no change,

Actually i want the  bar color to be changed

Author

Commented:
i tried Background setting, but the barcolor has not been set,and with Foreground also no change,

Actually i want the  bar color to be changed
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Could be related to the following bug:

http://developer.java.sun.com/developer/bugParade/bugs/4195048.html

Whick JDK, L&F are u using?
Have you tried different L&F's?

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
If you want to change colour for all scroll bars then you could also try changing the default via UIManager.

Commented:
I tried it out in JDK 1.3 using the Metal L&F. Calling setBackground(), the area that the slider moves in will change to the specified color, but the slider and the arrows are not affected. Calling setForeground() has no effect on any part of the scrollbar.

Author

Commented:
i tried Background setting, but the barcolor has not been set,and with Foreground also no change,

Actually i want the  bar color to be changed

Author

Commented:
iam using JDK1.2 and Metal L&F ,

cna u please give the code of changing the default via UIManager.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
UIManager.put(property, color);

where property is one of:
"ScrollBar.thumbHighlight"
"ScrollBar.thumbLightHighlight"
"ScrollBar.thumbDarkHighlight"
"ScrollBar.thumb"
"ScrollBar.track"
"ScrollBar.trackHighlight"


Author

Commented:
hi objects , iam unable to set the color using what you gave above, will there be any solution for this.
becuase for my project all designing is completed, only these comboboxes when clicked looks ugly,


Author

Commented:
Hi objects, thankyou very much,
now i got it,
i used the same u gave, now its working,
can u tell me how to grade your answer,

thankyou
javamahesh
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
There should be a button somewhere.