Article View: borland.public.jbuilder.java.swing
Article #10656Re: multi-line text on JLabel or JButton possible?
From: Ze'ev Bubis
Date: Wed, 25 Aug 1999 00:00
Date: Wed, 25 Aug 1999 00:00
105 lines
3692 bytes
3692 bytes
--------------70B92134510CB6FE9F3A6CA3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
Here is an implementation of a multi-line label - it simply takes a text
area and changes its look and feel to disguise the text area as a label.
(This was take from the book "Graphic JAVA 2 - Mastering the JFC" by David M.
Geary)
class MultilineLabel extends JTextArea
{
public MultilineLabel(String s)
{
super(s);
}
public void updateUI()
{
super.updateUI();
// turn on wrapping and disable editing and highlighting
setLineWrap(true);
setWrapStyleWord(true);
setHighlighter(null);
setEditable(false);
// Set the text area's border, colors and font to
// that of a label
LookAndFeel.installBorder(this, "Label.border");
LookAndFeel.installColorsAndFont(this,
"Label.background",
"Label.foreground",
"Label.font");
}
}
Lois Neo wrote:
> Hi,
>
> If I have a long label to display on a JLabel or a JButton, is it possible
> to display in multiple lines?
> Is it also possible for the tooltip case?
>
> --
> Thanks for any help given
>
> Lois
--------------70B92134510CB6FE9F3A6CA3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<br> Here is an implementation of a multi-line label - it simply
takes a text area and changes its look and feel to disguise the text area
as a label.
<br>(This was take from the book "Graphic JAVA 2 - Mastering the JFC" by
David M. Geary)
<br>
<p><tt>class MultilineLabel extends JTextArea</tt>
<br><tt>{</tt>
<br><tt> public MultilineLabel(String s)</tt>
<br><tt> {</tt>
<br><tt> super(s);</tt>
<br><tt> }</tt>
<br><tt> </tt>
<br><tt> public void updateUI()</tt>
<br><tt> {</tt>
<br><tt> super.updateUI();</tt><tt></tt>
<p><tt> // turn on wrapping and disable editing and highlighting</tt><tt></tt>
<p><tt> setLineWrap(true);</tt>
<br><tt> setWrapStyleWord(true);</tt>
<br><tt> setHighlighter(null);</tt>
<br><tt> setEditable(false);</tt><tt></tt>
<p><tt> // Set the text area's border, colors and font to</tt>
<br><tt> // that of a label</tt><tt></tt>
<p><tt> LookAndFeel.installBorder(this, "Label.border");</tt><tt></tt>
<p><tt> LookAndFeel.installColorsAndFont(this,</tt>
<br><tt> "Label.background",</tt>
<br><tt> "Label.foreground",</tt>
<br><tt> "Label.font");</tt>
<br><tt> }</tt>
<br><tt>}</tt>
<br>
<p>Lois Neo wrote:
<blockquote TYPE=CITE>Hi,
<p>If I have a long label to display on a JLabel or a JButton, is it possible
<br>to display in multiple lines?
<br>Is it also possible for the tooltip case?
<p>--
<br>Thanks for any help given
<p>Lois</blockquote>
</html>
--------------70B92134510CB6FE9F3A6CA3--
Technical Details
Message-ID:
<37C41600.CA7DA113@globaloop.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7po0q8$c7a12@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,da0b2f7d3222ae8a X-Google-Attributes: gid111d45,public From: Ze'ev Bubis <zeevb@globaloop.com> Subject: Re: multi-line text on JLabel or JButton possible? Date: 1999/08/25 Message-ID: <37C41600.CA7DA113@globaloop.com> X-Deja-AN: 517042209 References: <7po0q8$c7a12@forums.borland.com> X-Accept-Language: en Content-Type: multipart/alternative; boundary="------------70B92134510CB6FE9F3A6CA3" Organization: GlobaLoop LTD. Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing