Short question about JSlider

A

aurengo

Hi,

I have a problem with the font of JSlider labels.
This code compiles but does not work and I am wondering how I can set
the label font :

JSlider s = new JSlider(JSlider.HORIZONTAL,min,max,value);
Font f = new Font("Monaco", Font.PLAIN,9);
s.setFont(f);
....

Thanks for your help and suggestions
 
B

Ben Kraufmann

Hi,

I have a problem with the font of JSlider labels.
This code compiles but does not work and I am wondering how I can set
the label font :

JSlider s = new JSlider(JSlider.HORIZONTAL,min,max,value);
Font f = new Font("Monaco", Font.PLAIN,9);
s.setFont(f);
...

Thanks for your help and suggestions


Hi,

it's a known bug that JSlider ignores setFont().
So, extending JSlider with your own labels may be a good idea.
Or getting in touch with Java6? ;)

Ben
 
M

Michael Rauscher

Ben said:
Hi,

it's a known bug that JSlider ignores setFont().

It's not a bug, it's a feature (although I've to admit that it would
have been nice if the slider's font had been taken into account):

http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html
So, extending JSlider with your own labels may be a good idea.

That is a bad idea. The OP simply needs to do what the documentation
tells him to do:

Font font = slider.getFont();
Dictionary dict = slider.getLabelTable();
for ( Enumeration e = dict.elements(); e.hasMoreElements(); ) {
Object element = e.nextElement();
if ( element instanceof JComponent ) {
((JComponent)element).setFont( font );
}
}

Bye
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top