🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10987

Re: Changing of fonts

#10987
From: Jackie Roehl
Date: Sat, 24 Jul 1999 00:00
41 lines
1822 bytes
Hi Lois,
I ran into this problem with several JTextFields.  I needed to be able to
'toggle' the text between Plain and Bold.

I don't know why the setFont won't accept a change of style alone.  I ended up
having a Font variable with the Plain font setting and using that to reset the
values.

Example
JTextField aField = new JTextField("some text");
//aField's font style = Plain
Font defaultFont = aField.getFont();

//set to BOLD
aField.setFont(new Font(aField.getFont().getFontName(), Font.BOLD, 14);

//now need to reset to plain
aField.setFont(defaultFont);

Hope that helps.
Jackie

Lois Neo wrote:

> Hi,
>
> I need to apply change of font face, styles & size dynamically during run
> time on a JLabel. Now I find that once a font say, "Times New Roman, PLAIN,
> 15" has been set before, changing to another font style, say BOLD, is not
> reflected on the Text of the JLabel at all. However, if I change the font
> size, the change (both style & size) is then reflected. What's wrong?
>
> Every time I want to change the font, I call the following codes:
>       myLabel.setText(myText);
>       myLabel.setFont(new Font(fontName,fontStyle, fontSize));
>       myLabel.repaint();
>
> --
> Thanks for any help given
>
> Lois
Technical Details
Message-ID: <3799DBDD.BF8A918@jhuapl.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7na64r$p884@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,90757db6ba04624e
X-Google-Attributes: gid111d45,public
From: Jackie Roehl <Jackie.Roehl@jhuapl.edu>
Subject: Re: Changing of fonts
Date: 1999/07/24
Message-ID: <3799DBDD.BF8A918@jhuapl.edu>
X-Deja-AN: 504760922
Content-Transfer-Encoding: 7bit
References: <7na64r$p884@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing