🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

JList problem with selection

#12617
From: Anne JANSSENS
Date: Wed, 02 Dec 1998 00:00
87 lines
3923 bytes
hi all, here is my problem !
I haved defined my own listCellRenderer to have in my JList : JCeckBox or
JRadioButton.
When I select a button, in my renderer, I test isSelected to see if this
item is selected, and then
I ask the button to get a specific background color to show the selection.
it doesn't work !
Can anyone help ?
:)Anne

here is the code of my cellRenderer :

public class oj_listeCellRenderer implements ListCellRenderer,include_gen
{  private oj_liste  monparent;
   private Icon      mon_icone;
   private int   type_liste;
   private boolean   selectionne;

 public oj_listeCellRenderer(oj_liste leparent, int type)
 {  monparent=leparent;
      type_liste=type;
   }

    public Component getListCellRendererComponent ( JList list,
                                                   Object value,
                                                   int index,
                                                   boolean isSelected,
                                                   boolean cellHasFocus)
   { switch (type_liste)
     { case TYPE_LISTE : { JLabel un_composant=new JLabel(value.toString())
             {
                           };

un_composant.setHorizontalAlignment(JLabel.CENTER);
                           if
(monparent.ecr_liste_element_non_selectionnable(index))
                           { un_composant.setForeground(Color.gray);
                           }
             un_composant.setFont(monparent.ecr_liste_font_get());
                           return un_composant;
                         };
       case TYPE_CASE : { JCheckBox un_composant=new
JCheckBox(value.toString());
                          /* si le composant n'est pas selctionnable ->
enabled(false) */
                          if
(monparent.ecr_liste_element_non_selectionnable(index))
                          { un_composant.setEnabled(false);
                          }
                          if (isSelected)
                          { if
(monparent.ecr_liste_element_non_selectionnable(index))
                            { un_composant.setEnabled(false);
                            }
                            else
                            {  un_composant.setSelected(true);
                               /* on met en couleur le fond du bouton */
                               un_composant.setBackground(Color.cyan);
                           }
                          }
                          return un_composant;
                        };
       case TYPE_RADIO :{ JRadioButton un_composant=new
JRadioButton(value.toString());
               /* si le composant n'est pas selectionnable -> enabled(false)
*/
                          if
(monparent.ecr_liste_element_non_selectionnable(index))
                          {  un_composant.setEnabled(false);
                          }
                          if (isSelected)
                          {  if
(monparent.ecr_liste_element_non_selectionnable(index))
                             {  un_composant.setEnabled(false);
                             }
                             else
                             { un_composant.doClick();
                               /* on met en couleur le fond du bouton */

                             }
                          }
                          return un_composant;
                        };
     }
     return null;
  }
}
Technical Details
Message-ID: <743q0g$qha1@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,14b6b67332adf1b4,start
X-Google-Attributes: gid111d45,public
From: "Anne JANSSENS" <recherche@generix.fr>
Subject: JList problem with selection
Date: 1998/12/02
Message-ID: <743q0g$qha1@forums.borland.com>
X-Deja-AN: 417894853
Organization: Another Netscape Collabra Server User
X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4
Newsgroups: borland.public.jbuilder.java.swing