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

T

Tom Parson

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
 
V

VisionSet

Tom Parson said:
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
 
O

Oliver Wong

Tom Parson said:
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
 
T

Thomas Fritsch

Tom said:
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);
 
I

IchBin

Tom said:
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-)
 
S

Steve W. Jackson

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 =
 
K

Knute Johnson

Tom said:
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));
}
}
 
Z

zero

(e-mail address removed) (Tom Parson) wrote in
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
 
M

Michael Rauscher

Tom said:
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
 
R

Redbeard

Tom said:
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
 
J

Jason

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));
 
B

Benoit Peltier

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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top