Article View: borland.public.jbuilder.java.swing
Article #11905Re: right-alignment in JList
From: Anne JANSSENS
Date: Fri, 12 Mar 1999 00:00
Date: Fri, 12 Mar 1999 00:00
118 lines
5877 bytes
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> </DIV>
<DIV>for example you can ask you item to be shown as JLabel :</DIV>
<DIV> </DIV>
<DIV>public class my_listeCellRenderer extends JLabel implements=20
ListCellRenderer,<BR><BR>{ public=20
my_listeCellRenderer()<BR> { =20
<BR> =20
this.setOpaque(true);<BR> }</DIV>
<DIV> </DIV>
<DIV> public Component getListCellRendererComponent ( =
JList=20
list,<BR> &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p; =20
Object=20
value,<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; =20
int=20
index,<BR> &nb=
sp; &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; =20
boolean=20
isSelected,<BR> &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p; =20
boolean cellHasFocus)<BR> {=20
this.setText(value.toString());<BR> =20
this.setHorizontalAlignment(JLabel.RIGHT);<BR> =
return=20
this;<BR> };</DIV>
<DIV>}</DIV>
<DIV> </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> </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-mailReferences:
<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