🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: multi-line text on JLabel or JButton possible?

#10656
From: Ze'ev Bubis
Date: Wed, 25 Aug 1999 00:00
105 lines
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>&nbsp; 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>&nbsp;
<p><tt>class MultilineLabel extends JTextArea</tt>
<br><tt>{</tt>
<br><tt>&nbsp;public MultilineLabel(String s)</tt>
<br><tt>&nbsp;{</tt>
<br><tt>&nbsp; super(s);</tt>
<br><tt>&nbsp;}</tt>
<br><tt>&nbsp;</tt>
<br><tt>&nbsp;public void updateUI()</tt>
<br><tt>&nbsp;{</tt>
<br><tt>&nbsp; super.updateUI();</tt><tt></tt>
<p><tt>&nbsp; // turn on wrapping and disable editing and highlighting</tt><tt></tt>
<p><tt>&nbsp; setLineWrap(true);</tt>
<br><tt>&nbsp; setWrapStyleWord(true);</tt>
<br><tt>&nbsp; setHighlighter(null);</tt>
<br><tt>&nbsp; setEditable(false);</tt><tt></tt>
<p><tt>&nbsp; // Set the text area's border, colors and font to</tt>
<br><tt>&nbsp; // that of a label</tt><tt></tt>
<p><tt>&nbsp; LookAndFeel.installBorder(this, "Label.border");</tt><tt></tt>
<p><tt>&nbsp; LookAndFeel.installColorsAndFont(this,</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Label.background",</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Label.foreground",</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Label.font");</tt>
<br><tt>&nbsp;}</tt>
<br><tt>}</tt>
<br>&nbsp;
<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-mail
References: <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