How to increase the Fontsize in a JLable or on a JButton ?

Discussion in 'Java' started by Tom Parson, Nov 18, 2005.

  1. Tom Parson

    Tom Parson Guest

    I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    from normal/default to a bigger size.

    How do I specify a bigger font size?

    Tom
    Tom Parson, Nov 18, 2005
    #1
    1. Advertising

  2. Tom Parson

    VisionSet Guest

    "Tom Parson" <> wrote in message
    news:437dfebd$0$21940$-online.net...
    > I would like to increase the font size for a JLabel or JButton (in a

    GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >



    Without looking at the API, something you should do...

    myComponent.setFont(myComponent.deriveFont(mySize))

    or something very similar, look at java.awt.Font

    --
    Mike W
    VisionSet, Nov 18, 2005
    #2
    1. Advertising

  3. Tom Parson

    Oliver Wong Guest

    "Tom Parson" <> wrote in message
    news:437dfebd$0$21940$-online.net...
    >I would like to increase the font size for a JLabel or JButton (in a
    >GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?


    JComponent (which JLabel and JButton extend) has a setFont() method.

    - Oliver
    Oliver Wong, Nov 18, 2005
    #3
  4. Tom Parson wrote:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?

    Just by setting a font with a size bigger than the default size of 12
    onto your JLabel. For example:
    JLabel label = ...;
    Font f = new Font("Dialog", Font.PLAIN, 24);
    label.setFont(f);

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Nov 18, 2005
    #4
  5. Tom Parson

    IchBin Guest

    Tom Parson wrote:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom
    >


    JMyLable.setFont(new Font("Dialog", 1, 14))
    JMyButton.setFont(new Font("Dialog", 1, 14))

    --


    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
    IchBin, Nov 18, 2005
    #5
  6. In article <437dfebd$0$21940$-online.net>,
    (Tom Parson) wrote:

    > I would like to increase the font size for a JLabel or JButton (in a
    > GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom


    Both inherit the getFont method from Container. You can retrieve the
    current font to learn whatever you need to about it and create one of a
    larger size. Then use the setFont method that both inherit from
    JComponent. This all assumes you're wanting to do this for any given
    label or button, not for all.

    = Steve =
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Nov 18, 2005
    #6
  7. Tom Parson wrote:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom
    >


    public class TomsJLabel extends JLabel {
    public TomsJLabel(String text) {
    super(text);
    Font f = getFont();
    Float s = f.getSize2D();
    s += 6.0f; // six points bigger
    setFont(f.deriveFont(s));
    }
    }

    --

    Knute Johnson
    email s/nospam/knute/
    Knute Johnson, Nov 18, 2005
    #7
  8. Tom Parson

    zero Guest

    (Tom Parson) wrote in
    news:437dfebd$0$21940$-online.net:

    > I would like to increase the font size for a JLabel or JButton (in a
    > GridBagLayout) from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom
    >


    I believe JLabel and JButton have (limited) html support. If you don't
    want to bother with fonts, try feeding them <html><font size="2em">text
    </font></html>

    Note: I haven't tested this, just giving some ideas
    zero, Nov 18, 2005
    #8
  9. Tom Parson

    Roedy Green Guest

    Roedy Green, Nov 18, 2005
    #9
  10. Tom Parson schrieb:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?


    If it's just for specific elements, you may use setFont, e.g.

    myLabel.setFont(myLabel.getFont().deriveFont(12.0f));

    Otherwise you'd have to set the corresponding property of your laf.

    Bye
    Michael
    Michael Rauscher, Nov 19, 2005
    #10
  11. Tom Parson

    Redbeard Guest

    Tom Parson wrote:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom


    Here is an example.
    JButton button = new JButton("Text"); //instantiate JButton
    Font font1 = button.getFont(); //get the current font
    Font font2 = font1.deriveFont(20); //create a second font object that
    //is the same as
    font1, but has
    //a specified size
    button.setFont(font2); //set the font to the second font object

    Here is a link to an online version of the documentation. I found the
    solution by reading it.
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    Redbeard, Nov 23, 2005
    #11
  12. Tom Parson

    Jason Guest

    the 3rd parameter in the java.awt.Font constructor (the number 24 in
    the example below) is the size of the font...

    myButton.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 24));


    Tom Parson wrote:
    > I would like to increase the font size for a JLabel or JButton (in a GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom
    Jason, Nov 28, 2005
    #12
  13. Hello Tom

    If you want to keep the same Font but only bigger, here is a simple way :

    label.setFont( label.getFont().deriveFont( 16.0f ) );

    Hope it helps,

    Ben



    "Tom Parson" <> wrote in message
    news:437dfebd$0$21940$-online.net...
    >I would like to increase the font size for a JLabel or JButton (in a
    >GridBagLayout)
    > from normal/default to a bigger size.
    >
    > How do I specify a bigger font size?
    >
    > Tom
    >
    Benoit Peltier, Jan 11, 2006
    #13
    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. =?Utf-8?B?ZnJlZA==?=

    fontsize/stylesheet problem

    =?Utf-8?B?ZnJlZA==?=, Jun 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    425
    =?Utf-8?B?ZnJlZA==?=
    Jun 9, 2004
  2. Veeresh

    HTML Literal Control & FontSize

    Veeresh, Jun 28, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,325
    Veeresh
    Jun 28, 2004
  3. Tushar
    Replies:
    1
    Views:
    293
    Thomas Weidenfeller
    Feb 14, 2005
  4. Samuël van Laere

    Fontsize questions

    Samuël van Laere, Nov 20, 2003, in forum: HTML
    Replies:
    9
    Views:
    401
    Samuël van Laere
    Nov 21, 2003
  5. JL
    Replies:
    1
    Views:
    736
Loading...

Share This Page