Short question about JSlider

Discussion in 'Java' started by aurengo@wanadoo.fr, Aug 24, 2006.

  1. Guest

    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
     
    , Aug 24, 2006
    #1
    1. Advertising

  2. On Thu, 24 Aug 2006 22:15:08 +0200, aurengo wrote:

    > 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
     
    Ben Kraufmann, Aug 24, 2006
    #2
    1. Advertising

  3. Ben Kraufmann schrieb:
    > On Thu, 24 Aug 2006 22:15:08 +0200, aurengo wrote:
    >
    >> 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().


    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
     
    Michael Rauscher, Aug 24, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Boxer

    JSlider Question

    Aaron Boxer, Oct 23, 2003, in forum: Java
    Replies:
    2
    Views:
    624
    Phil...
    Oct 24, 2003
  2. Konrad Den Ende
    Replies:
    0
    Views:
    897
    Konrad Den Ende
    Dec 12, 2004
  3. Replies:
    2
    Views:
    1,328
  4. Simon Andrews

    Removing numbers over JSlider

    Simon Andrews, Apr 21, 2008, in forum: Java
    Replies:
    0
    Views:
    387
    Simon Andrews
    Apr 21, 2008
  5. A Watcher

    JSlider changeEvent and Matlab

    A Watcher, Jun 26, 2008, in forum: Java
    Replies:
    0
    Views:
    401
    A Watcher
    Jun 26, 2008
Loading...

Share This Page