Article View: borland.public.jbuilder.java.swing
Article #1173Re: Someone have example jList ListCellRenderer example?
From: John McGrath [TeamB]
Date: Sat, 20 Mar 2004 21:55
Date: Sat, 20 Mar 2004 21:55
64 lines
2902 bytes
2902 bytes
On 3/20/2004 at 8:28:45 AM, nospam wrote:
> The best I can to is check a box, but not uncheck it.
> I've tried NUMEROUS permutations of this.
> if (cellHasFocus) {
> if (isSelected) {
> setSelected(false);
> }
> else {
> setSelected(true);
> }
>
> System.out.print("GOT HERE");
> }
A cell renderer is an object that provides a Component that will be
used to do the painting. Normally, the getListCellRendererComponent()
method will configure the properties of the Component so it will render
the cell appropriately.
As is often the case, this cell renderer returns the same component
each time getListCellRendererComponent() is called. Since the above
code configures the "Selected" property only if cellHasFocus is true,
it will be left in whatever state it was in previous time it was used.
So you need to change the code to set the "Selected" property even when
"cellHasFocus" is false.
if (cellHasFocus) {
if (isSelected) {
setSelected(false);
}
else {
setSelected(true);
}
}
else {
setSelected(true);
}
Of course, these 11 lines of code could be replace with the following
single line:
setSelected( cellHasFocus & !isSelected );
This is much simpler and more efficient and it also makes it far more
clear that the "Selected" property will always be set.
> From: nospam <no@spam.com>
BTW, many people frown on anonymous messages. I can understand why you
might want to omit your e-mail address, but I can think of no reason to
omit your name.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<405cbdd0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<pan.2004.03.17.02.25.29.868166@spam.com> <405a7347@newsgroups.borland.com> <pan.2004.03.20.04.55.47.68889@spam.com> <405bed9f@newsgroups.borland.com> <pan.2004.03.20.13.28.44.699216@spam.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,de66bf01ed98544f X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-20 13:59:23 PST From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: Someone have example jList ListCellRenderer example? Newsgroups: borland.public.jbuilder.java.swing References: <pan.2004.03.17.02.25.29.868166@spam.com> <405a7347@newsgroups.borland.com> <pan.2004.03.20.04.55.47.68889@spam.com> <405bed9f@newsgroups.borland.com> <pan.2004.03.20.13.28.44.699216@spam.com> User-Agent: XanaNews/1.16.1.11 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 151.197.214.141 Message-ID: <405cbdd0@newsgroups.borland.com> Date: 20 Mar 2004 13:55:28 -0800 X-Trace: newsgroups.borland.com 1079819728 151.197.214.141 (20 Mar 2004 13:55:28 -0800) Lines: 64 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail