Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to increase the Fontsize in a JLable or on a JButton ?

Reply
Thread Tools

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

 
 
Tom Parson
Guest
Posts: n/a
 
      11-18-2005
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

 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      11-18-2005

"Tom Parson" <(E-Mail Removed)> wrote in message
news:437dfebd$0$21940$(E-Mail Removed)-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


 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      11-18-2005

"Tom Parson" <(E-Mail Removed)> wrote in message
news:437dfebd$0$21940$(E-Mail Removed)-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


 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      11-18-2005
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(' $','@')

 
Reply With Quote
 
IchBin
Guest
Posts: n/a
 
      11-18-2005
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-)
 
Reply With Quote
 
Steve W. Jackson
Guest
Posts: n/a
 
      11-18-2005
In article <437dfebd$0$21940$(E-Mail Removed)-online.net>,
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      11-18-2005
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/
 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      11-18-2005
(E-Mail Removed) (Tom Parson) wrote in
news:437dfebd$0$21940$(E-Mail Removed)-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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-18-2005
On 18 Nov 2005 16:18:05 GMT, (E-Mail Removed) (Tom Parson) wrote,
quoted or indirectly quoted someone who said :

>
>How do I specify a bigger font size?


setFont( new Font ( .... ) );

See http://mindprod.com/jgloss/gettingstarted.html
http://mindprod.com/jgloss/font.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Michael Rauscher
Guest
Posts: n/a
 
      11-19-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to increase fontsize javascript JL HTML 1 03-03-2009 09:24 PM
How to set the fontsize of labels in Applets Tushar Java 1 02-14-2005 08:50 AM
HTML Literal Control & FontSize Veeresh ASP .Net 2 06-28-2004 07:08 PM
fontsize/stylesheet problem =?Utf-8?B?ZnJlZA==?= ASP .Net 0 06-09-2004 08:56 AM
Fontsize questions SamuŽl van Laere HTML 9 11-21-2003 12:38 AM



Advertisments