Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2007

Tip: Looking for answers? Try searching our database.

List cell renderer with JLabel: selected border

Thread view: 
Karsten Wutzke - 09 Oct 2007 11:19 GMT
Hello!

When using a custom cell renderer (JLabel subclass), I noticed the
border of a selected item is not drawn. How can I achieve a border
like with the default renderer, the "yellow dots" around the entries,
as with a standard JList or JTree for example.

How do I do it? Change the JLabel super class to ...?

Karsten

PS: I need icons to be displayed on the left hand side.
Håkan Lane - 11 Oct 2007 18:21 GMT
I think that you will have to write your own subclass of some
CellRenderer class. In what context (JList, JTree et.c) are you using
your JLabel? What you need to do would depend on that. I just spent
several hours learning this stuff today, so I don't mind helping you.
Just post some details about your code.

Håkan
Karsten Wutzke - 12 Oct 2007 13:43 GMT
On 11 Okt., 19:21, H?kan Lane <H...@operamail.com> wrote:
> I think that you will have to write your own subclass of some
> CellRenderer class. In what context (JList, JTree et.c) are you using
[quoted text clipped - 3 lines]
>
> H?kan

I'm using it in a JList. I already created a list cell renderer.
There's nothing special or otherwise difficult about the code in that
renderer class. When highlighting an entry in the list, I just miss
the "dotted border", as with standard JList or JTree entries.

What I mean here is I think, the border that gets displayed when the
entry is *focussed*...

Karsten
Håkan Lane - 14 Oct 2007 17:37 GMT
> I'm using it in a JList. I already created a list cell renderer.
> There's nothing special or otherwise difficult about the code in that
[quoted text clipped - 5 lines]
>
> Karsten

Did you solve the problem with the answer that Bent C Dalager gave?

Håkan
Bent C Dalager - 11 Oct 2007 18:44 GMT
>Hello!
>
[quoted text clipped - 4 lines]
>
>How do I do it? Change the JLabel super class to ...?

You typically call label.setBorder() with an appropriate Border
object.

Swing apparantly uses
UIManager.getBorder("Table.focusSelectedCellHighlightBorder")
when that is available, and
UIManager.getBorder("Table.focusCellHighlightBorder")
when it is not.

(This is from the source for
javax.swing.table.DefaultTableCellRenderer in Java 1.6. Other versions
may be different.)

>Karsten
>
>PS: I need icons to be displayed on the left hand side.

If you want the icons to be to the left of the border, then you would
need to have a JPanel with two JLabels inside it. One JLabel would be
to the left and hold the icons but show no border while the other
JLabel would be to the right and hold the text as well as the border.

Cheers
    Bent D
Signature

Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd
                                   powered by emacs



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.