🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Changing of fonts

#10988
From: Jackie Roehl
Date: Sat, 24 Jul 1999 00:00
130 lines
4731 bytes
--------------ADD33AE18C433D9D8F1810F4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

One of the lines had an error --

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

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

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

Sorry about that.

Jackie Roehl wrote:

> 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

--------------ADD33AE18C433D9D8F1810F4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
One of the lines had an error --
<p><font color="#3333FF">&nbsp;</font>Example
<br>JTextField aField = new JTextField("some text");
<br>//aField's font style = Plain
<br><font color="#3333FF">Font defaultFont = new Font(aField.getFont().getFontName,
Font.PLAIN, 14 );</font>
<p>//set to BOLD
<br>aField.setFont(new Font(aField.getFont().getFontName(), Font.BOLD,
14);
<p>//now need to reset to plain
<br>aField.setFont(defaultFont);
<p>Sorry about that.
<p>Jackie Roehl wrote:
<blockquote TYPE=CITE>Hi Lois,
<br>I ran into this problem with several JTextFields.&nbsp; I needed to
be able to
<br>'toggle' the text between Plain and Bold.
<p>I don't know why the setFont won't accept a change of style alone.&nbsp;
I ended up
<br>having a Font variable with the Plain font setting and using that to
reset the
<br>values.
<p>Example
<br>JTextField aField = new JTextField("some text");
<br>//aField's font style = Plain
<br>Font defaultFont = aField.getFont();
<p>//set to BOLD
<br>aField.setFont(new Font(aField.getFont().getFontName(), Font.BOLD,
14);
<p>//now need to reset to plain
<br>aField.setFont(defaultFont);
<p>Hope that helps.
<br>Jackie
<p>Lois Neo wrote:
<p>> Hi,
<br>>
<br>> I need to apply change of font face, styles &amp; size dynamically
during run
<br>> time on a JLabel. Now I find that once a font say, "Times New Roman,
PLAIN,
<br>> 15" has been set before, changing to another font style, say BOLD,
is not
<br>> reflected on the Text of the JLabel at all. However, if I change
the font
<br>> size, the change (both style &amp; size) is then reflected. What's
wrong?
<br>>
<br>> Every time I want to change the font, I call the following codes:
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myLabel.setText(myText);
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myLabel.setFont(new Font(fontName,fontStyle,
fontSize));
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myLabel.repaint();
<br>>
<br>> --
<br>> Thanks for any help given
<br>>
<br>> Lois</blockquote>
</html>

--------------ADD33AE18C433D9D8F1810F4--
Technical Details
Message-ID: <3799DD27.A5D008F9@jhuapl.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7na64r$p884@forums.borland.com> <3799DBDD.BF8A918@jhuapl.edu>

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: <3799DD27.A5D008F9@jhuapl.edu>
X-Deja-AN: 504763597
References: <7na64r$p884@forums.borland.com> <3799DBDD.BF8A918@jhuapl.edu>
X-Accept-Language: en
Content-Type: multipart/alternative; boundary="------------ADD33AE18C433D9D8F1810F4"
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing