🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JComboBox--color of selection

#10238
From: enisoc
Date: Mon, 01 Nov 1999 00:00
50 lines
2276 bytes
as far as I can tell, the only way to do this is to set the JComboBox's
ListCellRenderer with the setRenderer method. it takes an argument of the
interface ListCellRenderer. here's the example from the jdk docs:

class MyCellRenderer extends JLabel implements ListCellRenderer {
     public MyCellRenderer() {
         setOpaque(true);
     }
     public Component getListCellRendererComponent(
         JList list,
         Object value,
         int index,
         boolean isSelected,
         boolean cellHasFocus)
     {
         setText(value.toString());
         setBackground(isSelected ? Color.red : Color.white);
         setForeground(isSelected ? Color.white : Color.black);
         return this;
     }
 }

it returns a label with custom colors. i've done some pretty strange things
with this mechanism in the name of boredom.

hope this helps,
Anthony

Kevin Dwan <kevin@blueberry.com> wrote in message
news:381D92CF.DB356BB8@blueberry.com...
> I'm populating a JComboBox with an array of strings. (JB3)
>
> I've set Background Color to Light Gray, and the initial selection in
> the box appears gray. However, when the user changes to another
> selection, the new string displays (in my configuration) as a dark blue
> background. This color remains until the user puts focus somewhere
> outside the box.
>
> I'd like the string that displays in the box to always be the same
> color. Can someone suggest a way to do that?
>
> I'm not sure this is what I want to do, but is there also a way for the
> background of the scrollable list (array, actually) to not be white, but
> gray or some other color I specify, without having to write a Custom
> Renderer?
>
> Thx.
>
>
>
Technical Details
Message-ID: <7vl01k$7j317@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <381D92CF.DB356BB8@blueberry.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,4dd336fbb83ddbd7
X-Google-Attributes: gid111d45,public
From: "enisoc" <enisoc@hotpop.com>
Subject: Re: JComboBox--color of selection
Date: 1999/11/01
Message-ID: <7vl01k$7j317@forums.borland.com>
X-Deja-AN: 543239039
References: <381D92CF.DB356BB8@blueberry.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.swing