f



Underlining text in JLabel

Hi
I am looking for an example code on how to underline text displayed in JLabel. 

thanks for any help
Hari
0
hari
9/23/2003 4:14:24 PM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

7 Replies
8219 Views

Similar Articles

[PageSpeed] 34

In article <f4ce927d.0309230814.1c2dfade@posting.google.com>,
 hari.motati@gs.com (Hari) wrote:

>:Hi
>:I am looking for an example code on how to underline text displayed in 
>:JLabel. 
>:
>:thanks for any help
>:Hari

You can't actually underline text in a JLabel.  You can set its font, so 
perhaps you can some up with a font that includes underlines.  But an 
even simpler possibility would be to use HTML.  Let's see -- don't you 
underline text in HTML with <u> and </u> tags?  Then your JLabel's text 
value could be "<html><u>some text here</u></html>" and it should work.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama
1
Steve
9/23/2003 4:20:11 PM
hari.motati@gs.com (Hari) writes:

> I am looking for an example code on how to underline text displayed
> in JLabel.

theLabel.setText("<html>Look at the <u>underline</u>!");

Note that this causes HTML rendering instead of the JLabel's normal
font setting, so it will look out of place unless you start playing
with stylesheets.
0
Tor
9/23/2003 5:30:01 PM
In article <u7k3ze7l2.fsf@broadpark.no>,
 Tor Iver Wilhelmsen <tor.iver.wilhelmsen@broadpark.no> wrote:

>:hari.motati@gs.com (Hari) writes:
>:
>:> I am looking for an example code on how to underline text displayed
>:> in JLabel.
>:
>:theLabel.setText("<html>Look at the <u>underline</u>!");
>:
>:Note that this causes HTML rendering instead of the JLabel's normal
>:font setting, so it will look out of place unless you start playing
>:with stylesheets.

Why do you say that?  I've seen no evidence of it in our app's usage.  
We set the font on numerous JLabel or JButton instances, and in a small 
number we set the actual text using HTML (though we always close the 
tags).  And none have exhibited any unusual appearance or behavior.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama
0
Steve
9/23/2003 8:21:17 PM
On 23 Sep 2003 09:14:24 -0700, hari.motati@gs.com (Hari) wrote:

>Hi
>I am looking for an example code on how to underline text displayed in JLabel. 
>
>thanks for any help
>Hari

JLabel lbl = new JLabel("Blahblah");
lbl.setFont(new Font("Tahoma", Font.UNDERLINE, 10);

I don't know if this is correct, but I think it should work along those lines.
-1
Kevin
9/23/2003 8:22:28 PM
In article <eqa1nvgjudtfit16975n4o1rohhtggfsfi@4ax.com>,
 Kevin Pors <krpors@yahoo.deletethisportion.co.uk> wrote:

>:On 23 Sep 2003 09:14:24 -0700, hari.motati@gs.com (Hari) wrote:
>:
>:>Hi
>:>I am looking for an example code on how to underline text displayed in 
>:>JLabel. 
>:>
>:>thanks for any help
>:>Hari
>:
>:JLabel lbl = new JLabel("Blahblah");
>:lbl.setFont(new Font("Tahoma", Font.UNDERLINE, 10);
>:
>:I don't know if this is correct, but I think it should work along those 
>:lines.

Unfortunately, no.  There's no such thing as "Font.UNDERLINE" in the 
Font class definition.  The only styles are PLAIN, BOLD, and ITALIC, and 
the last two can be added to get both styles.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama
-1
Steve
9/23/2003 8:47:44 PM
"Steve W. Jackson" wrote:

> Why do you say that?  I've seen no evidence of it in our app's
> usage.  We set the font on numerous JLabel or JButton instances,
> and in a small number we set the actual text using HTML (though we
> always close the tags).  And none have exhibited any unusual
> appearance or behavior. 

When HTML labels were introduced, they indeed came up with a different 
font and alignment then the normal font on the the label. This was the 
case for a long time, and only fixed in recent VMs.

You still need HTML like 

    	button.setText("<html><font face=Dialog size=1><b>" 
    	    	    	+ text + 
			+ "</b></font></html>");

on older VMs.
0
Harald
9/24/2003 6:03:05 AM
In article <Xns940051F81FCFDhhtoken@194.97.5.9>,
 Harald Hein <speechless@gmx.de> wrote:

>:"Steve W. Jackson" wrote:
>:
>:> Why do you say that?  I've seen no evidence of it in our app's
>:> usage.  We set the font on numerous JLabel or JButton instances,
>:> and in a small number we set the actual text using HTML (though we
>:> always close the tags).  And none have exhibited any unusual
>:> appearance or behavior. 
>:
>:When HTML labels were introduced, they indeed came up with a different 
>:font and alignment then the normal font on the the label. This was the 
>:case for a long time, and only fixed in recent VMs.
>:
>:You still need HTML like 
>:
>:    	button.setText("<html><font face=Dialog size=1><b>" 
>:    	    	    	+ text + 
>:			+ "</b></font></html>");
>:
>:on older VMs.

That might explain why one of our uses of HTML on a JButton has 
something similar.  It was done quite some time ago, and I couldn't 
remember the rationale, since the person who actually coded it isn't 
with our team any longer.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama
0
Steve
9/24/2003 3:41:09 PM
Reply: