🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: right-alignment in JList

#11905
From: Anne JANSSENS
Date: Fri, 12 Mar 1999 00:00
118 lines
5877 bytes
This is a multi-part message in MIME format.

------=_NextPart_000_0020_01BE6C75.A6C93450
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

You can define a listCellRenderer to show your items in your list as you =
want !

for example you can ask you item to be shown as JLabel :

public class my_listeCellRenderer extends JLabel implements =
ListCellRenderer,

{    public my_listeCellRenderer()
     { =20
          this.setOpaque(true);
     }

    public Component getListCellRendererComponent ( JList list,
                                                                         =
                      Object value,
                                                                         =
                      int index,
                                                                         =
                      boolean isSelected,
                                                                         =
                      boolean cellHasFocus)
   { this.setText(value.toString());
     this.setHorizontalAlignment(JLabel.RIGHT);
     return this;
   };
}

you ask your JList to use your renderer by :
my_jlist.setCellRenderer(new my_listCellRenderer(this));

Hope it could help, :)Anne

------=_NextPart_000_0020_01BE6C75.A6C93450
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY>
<DIV>You can define a listCellRenderer to show your items in your list =
as you=20
want !</DIV>
<DIV>&nbsp;</DIV>
<DIV>for example you can ask you item to be shown as JLabel :</DIV>
<DIV>&nbsp;</DIV>
<DIV>public class my_listeCellRenderer extends JLabel implements=20
ListCellRenderer,<BR><BR>{&nbsp;&nbsp;&nbsp; public=20
my_listeCellRenderer()<BR>&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
this.setOpaque(true);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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
boolean cellHasFocus)<BR>&nbsp;&nbsp; {=20
this.setText(value.toString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
this.setHorizontalAlignment(JLabel.RIGHT);<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
return=20
this;<BR>&nbsp;&nbsp; };</DIV>
<DIV>}</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D3>you ask your JList to use =
your renderer=20
by :</FONT></DIV>
<DIV>my_jlist.setCellRenderer(new my_listCellRenderer(this));</DIV>
<DIV>&nbsp;</DIV>
<DIV>Hope it could help, :)Anne</DIV></BODY></HTML>

------=_NextPart_000_0020_01BE6C75.A6C93450--
Technical Details
Message-ID: <7cansr$n5618@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7c5uep$j9e1@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,e32ea4172f2e9043
X-Google-Attributes: gid111d45,public
From: "Anne JANSSENS" <recherche@generix.fr>
Subject: Re: right-alignment in JList
Date: 1999/03/12
Message-ID: <7cansr$n5618@forums.borland.com>
X-Deja-AN: 454141444
References: <7c5uep$j9e1@forums.borland.com>
Content-Type: multipart/alternative; boundary="----=_NextPart_000_0020_01BE6C75.A6C93450"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing