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 / August 2006

Tip: Looking for answers? Try searching our database.

Short question about JSlider

Thread view: 
aurengo@wanadoo.fr - 24 Aug 2006 21:15 GMT
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
Ben Kraufmann - 24 Aug 2006 21:58 GMT
On Thu, 24 Aug 2006 22:15:08 +0200, aurengo wrote:

> Hi,
>
[quoted text clipped - 8 lines]
>
> 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
Michael Rauscher - 24 Aug 2006 22:16 GMT
Ben Kraufmann schrieb:
> On Thu, 24 Aug 2006 22:15:08 +0200, aurengo wrote:
>
[quoted text clipped - 14 lines]
>
> 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


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.