🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to use JScrollPane

#8691
From: John P. McGrath
Date: Tue, 01 Aug 2000 00:00
54 lines
2065 bytes
On Mon, 31 Jul 2000 20:17:03 +0800, Scott Yaung wrote:

> Can you give me a sample,

I have not tested (or even compiled) this code, but it should give you an 
idea of how to proceed.

   class MyListCellRenderer
      implements ListCellRenderer
   {
      JLabel label;
      public MyListCellRenderer() {
         label = new JLabel();
         label.setOpaque( true );
      }
      public Component getListCellRendererComponent(
         JList list, Object value, int index, boolean isSelected,
         boolean cellHasFocus )
      {
         label.setText( ... );
         label.setIcon( ... );
         label.setForeground( ... );
         label.setBackground( ... );
         return label;
      }
   }

> 1st, I need some data related (a object )to the item

The "value" argument will be the item you added to the list.  Set the 
attributes of the JLabel based on its attributes.

> 2nd, each item have a different icon

No problem.  Set the icon as you wish.

> 3rd, the text of the item will with a darker shadow (option)

If JLabel can do what you want, then just set the attributes here.  If 
you need something fancier, find or create another component, and replace 
the JLabel with that component.

> 4th ,How about multi-column list ?

Instead of using a JLabel, you can create a custom component that draws 
several strings at the appropriate column positions.  Or you could use a 
JPanel with multiple labels in it.

Or you might want to look at JTable.

-- 
Regards,

John McGrath
Technical Details
Message-ID: <MPG.13f01e686a70d23f989a7d@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8m3jmu$h1c4@bornews.borland.com> <uaeeyimpv.fsf@sds.no> <8m3rib$l2f1@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,91b3c31e091d5875
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: How to use JScrollPane
Date: 2000/08/01
Message-ID: <MPG.13f01e686a70d23f989a7d@forums.borland.com>
X-Deja-AN: 653107078
References: <8m3jmu$h1c4@bornews.borland.com> <uaeeyimpv.fsf@sds.no> <8m3rib$l2f1@bornews.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing