Update Jcombobox 's label in render

hi ,everybody, i have a problem about combobox, any body can help me!
thank you!
I want to have a combobox with checkbox as item, I rewrite a render writen by ice, because the combobox has three state, when I click diferent checkbox in this combobox , the label of combobox will update rightly, but if I click one checkbox to change the checkbox state ,the label will no update , it seem that when I click one checkbox many times .the menthod
getListCellRendererComponent(JList list, Object value, int index,
                    boolean isSelected, boolean cellHasFocus)
will no update label
my code :
mainclass:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicComboBoxEditor;
public class mainclass {
      public static void main(String[] args) {
             final testbox myComboBox = new testbox();
             myComboBox.addItem("SelectAll");
             myComboBox.addItem("ClearAll");
             myComboBox.addItem("GrayedAll");
             for(int i = 0; i < 5; i++) {
                 myComboBox.addItem("Item " + i);
             JFrame frame = new JFrame("My ComboBox");
             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
             frame.setSize(150, 60);
             frame.setLocation(300, 300);
             //frame.setJMenuBar( menubar );
             JPanel panel=new JPanel();
             panel.setLayout(new BorderLayout());
             panel.add(myComboBox,BorderLayout.NORTH);        
             frame.getContentPane().add(panel);
             frame.setVisible(true);
             final IconedCellRendererField renderer = IconedCellRendererField.getCheckBoxRendererInstance();
             myComboBox.setRenderer(renderer);
             myComboBox.addActionListener(new ActionListener()
                 public void actionPerformed(ActionEvent e)
                      if(myComboBox.getSelectedItem().toString().equals("SelectAll")){
                           renderer.selectAll(true);                         
                      if(myComboBox.getSelectedItem().toString().equals("ClearAll")){
                           renderer.clearAll(true);
                      if(myComboBox.getSelectedItem().toString().equals("GrayedAll")){
                           renderer.grayedAll(true);
}renderer:
import java.awt.*;
import java.awt.event.*;
//import java.io.*;
//import java.net.*;
import java.util.*;
import javax.swing.*;
//import javax.swing.event.*;
import javax.swing.border.*;
//import javax.swing.table.*;
public class IconedCellRendererField extends DefaultListCellRenderer implements MouseListener {
     public Icon icon, selIcon;
     Icon[] icons = null;
     public boolean useIconBackground = true, useIndexSensitiveIcons = false,
               useCheckBoxAsIcon = false, useLinkState = false;
     Dimension labelDim = null;
     public JLabel iconLabel;
     public JCheckBox box = null;
     public JPanel noback;
     public SelectionStateHandler selStateHandler = null;     
     private JList theList = null;
     public boolean[] selState = null, enableState = null;
     int offset = 5;
     Rectangle rect = null;
     int currentLinkRow = -1;
     boolean isOnRow = false, paintDivider = false;
     private Icon dividerImage = null;     
     private Color linkColor = Color.blue, hoverColor = Color.red, selectedLinkColor = Color.green;
     /* Initialises the renderer with one icon that is displayed without the
      * cell background.
     public IconedCellRendererField(Icon icon) {
          this(icon,false);
     /* Initialises the renderer with two icons that provide a switch capability
      * when a row is selected/deselected
     public IconedCellRendererField(Icon icon, Icon selIcon) {
          this.icon = icon;
          this.selIcon = selIcon;
          //addMouseListener(this);
     /* Initialises the renderer with two icons that provide a switch capability
      * when a row is selected/deselected. The boolean argument enables the icon
      * to either use the renderer background or appear transparent.
     public IconedCellRendererField(Icon icon, Icon selIcon, boolean useIconBackground) {
          this(icon, selIcon);
          setIconHasBackground(useIconBackground);
          createNoBackgroundPanel();
     /* Initialises the renderer with a single no siwthing icon. The boolean
      * argument enables the icon to either use the renderer background
      * or appear transparent.
     public IconedCellRendererField(Icon icon, boolean useIconBackground) {
          this(icon, icon, useIconBackground);
     /* Initialises the renderer to load two icons from the provided image locations.
      * This enables icon switching on selection.
     public IconedCellRendererField(String iconLoc, String selIconLoc) {
          icon = new ImageIcon(iconLoc);
          selIcon = new ImageIcon(selIconLoc);
          //addMouseListener(this);
     /* Initialises the renderer to load a single icon from the provided image location.
      * The icon can either have the renderer background or not based on the
      * boolean property.
     public IconedCellRendererField(String iconLoc, boolean iconBackground) {
          this(iconLoc, iconLoc, iconBackground);
     /* Initialises the renderer to load two icons from the provided image locations.
      * This enables icon switching on selection. The icon can either have the renderer
      * background or not based on the boolean property.
     public IconedCellRendererField(String iconLoc, String selIconLoc, boolean iconBackground) {
          this(iconLoc, selIconLoc);
          setIconHasBackground(iconBackground);
          createNoBackgroundPanel();
     /* Initialises the renderer to load a single icon from the provided image location.
     public IconedCellRendererField(String iconLoc) {
          this(iconLoc, true);
     /* Initialises the renderer with an array of image icons that are repeated for
      * each row in the list.
     public IconedCellRendererField(Icon[] icons, boolean useIconBackground) {
          this(icons[0], icons[0], useIconBackground);
     public void createNoBackgroundPanel() {
          iconLabel = new JLabel((Icon)null, JLabel.CENTER);
          if(labelDim != null) {      iconLabel.setPreferredSize(labelDim); }
          iconLabel.setBorder( new EmptyBorder(1,5,1,5) );
          noback = new JPanel( new BorderLayout() ) {
              * Overridden for performance reasons.
              * See the <a href="#override">Implementation Note</a>
              * for more information.
              //public void validate() {}
             // public void invalidate() {}          
              public void repaint() {}
              //public void revalidate() {}
              public void repaint(long tm, int x, int y, int width, int height) {}
              public void repaint(Rectangle r) {}
              protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
                    // Strings get interned...
                    if (propertyName == "text"
                               || ((propertyName == "font" || propertyName == "foreground")
                                   && oldValue != newValue)) {
                        super.firePropertyChange(propertyName, oldValue, newValue);
              public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {}
              public void firePropertyChange(String propertyName, char oldValue, char newValue) {}
              public void firePropertyChange(String propertyName, short oldValue, short newValue) {}
              public void firePropertyChange(String propertyName, int oldValue, int newValue) {}
              public void firePropertyChange(String propertyName, long oldValue, long newValue) {}
              public void firePropertyChange(String propertyName, float oldValue, float newValue) {}
              public void firePropertyChange(String propertyName, double oldValue, double newValue) {}
              public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
          if(useCheckBoxAsIcon()) {
               box = new JCheckBox();
               //box.addMouseListener(this);
               box.setOpaque(false);
               noback.add( box, BorderLayout.WEST );
               //noback.addMouseListener(this);
               rect = box.getBounds();
               //list.addMouseListener(this);
          } else {
               noback.add( iconLabel, BorderLayout.WEST );
          noback.add( this, BorderLayout.CENTER );
          noback.setBorder( new EmptyBorder(1,1,1,1) );
          noback.setOpaque(false);
     public Component getListCellRendererComponent(JList list, Object value, int index,
                    boolean isSelected, boolean cellHasFocus) {
          System.out.println(value+"+"+index+"+"+isSelected+"+"+cellHasFocus);
          if(theList == null || theList != list) {
               theList = list;
               if(useLinkState) {
                    attachLinkSimulationListener();
          setOpaque(true);
          setText( value == null ? "" : value.toString());
          if(useIndexSensitiveIcons) {
               icon = getIcon(index);
          if(useIconBackground)
               setIcon(icon);          
          setFont( list.getFont() );
          setToolTipText(value.toString() );
          if(list.isEnabled())
               setEnabled( isEnabled(index) );
          else
               setEnabled( list.isEnabled() );
          if(isSelected && isEnabled(index) ) {
               setForeground( Color.black );
               setBackground( new Color(223, 235, 245) );
               if(useIndexSensitiveIcons) {
                    selIcon = getIcon(index);
               if(useIconBackground)
                    setIcon(selIcon);
          } else {
               setForeground(Color.black);
               setBackground(Color.white);
               setBorder(null);
          if(cellHasFocus) {
               setBorder( new CompoundBorder( new LineBorder( new Color(150, 150, 220) ),
                                                  new EmptyBorder(2,2,2,2)  ) );
          } else {
               setBorder( new EmptyBorder(2,2,2,2));
          if(useLinkState) {
               if(currentLinkRow == index) {
                    setText("<html><u>" + value.toString()+"</u></html>" );     
                    setForeground( getHoverLinkColor() );               
               } else {
                    setForeground( getLinkColor() );
               if(isSelected) {
                    setForeground( getSelectedLinkColor() );
               setBackground(Color.white);
               setBorder( new EmptyBorder(1,1,1,1) );
          if( shdPaintDivider() ) {
               Border border = null;
               if(dividerImage != null) {
                    border = new MatteBorder(0,0,1,0, dividerImage);
               } else {
                    border = new MatteBorder(0,0,1,0, getLinkColor() );
               if(index < theList.getModel().getSize() - 1 ) {
                    setBorder( new CompoundBorder(getBorder(),border) );
               } else {
                    setBorder( new EmptyBorder(1,1,1,1) );
          if(useIconBackground == false) {
              if(isSelected)
                  iconLabel.setIcon(selIcon);
              else
                  iconLabel.setIcon(icon);
              if(useCheckBoxAsIcon()) {
                  if(selState == null) {
                      updateSelectionStateTrackers(list);
                  if(selStateHandler == null) {
                      list.addMouseListener( selStateHandler = new SelectionStateHandler(list) );
                  try {
                      box.setSelected( selState[index] );
                  } catch(Exception e) {}
              if( shdPaintDivider() ) {              
                  //if(index < theList.getModel().getSize() - 1 ) {
                      noback.setBorder( getBorder() );
                      setBorder( new EmptyBorder(1,1,1,1) );
                  //} else {
                  //  noback.get
              // this should cause a JComboBox to paint the Label instead of the
              // check box + label combination
              if(index == -1) {
                   Vector<Object> v=new Vector<Object>();
                   v=getSelectedObjects();
                    String val=generateString();
                   JLabel label=new JLabel(val);                    
                  if(iconLabel.getIcon() != null) {
                       label.setIcon( iconLabel.getIcon() );
                  System.out.println("label");
                  return label;
              return noback;
          return this;
     public String generateString()
          String val = "";
          if(selState[0]==true&&selState[1]==false&&selState[2]==false){
                for(int i = 3; i < theList.getModel().getSize(); i++) {
                       String curString=theList.getModel().getElementAt(i).toString();
                       if(val.length()==0){
                              val=val+curString+"-1";
                       } else {                              
                              val=val+"&"+curString+"-1";
           //clear all     
           if(selState[1]==true&&selState[0]==false&&selState[2]==false ){                                   
                  for(int i = 3; i < theList.getModel().getSize(); i++) {
                       String curString=theList.getModel().getElementAt(i).toString();
                       if(val.length()==0){
                              val=val+curString+"-0";
                       } else {                              
                              val=val+"&"+curString+"-0";
          //grayedall
           if(selState[2]==true&&selState[0]==false&&selState[1]==false ){                                   
                  val="";                      
           if(selState[0]==false&&selState[1]==false&&selState[2]==false ){
                for(int i = 3; i < theList.getModel().getSize(); i++) {
                       String curString=theList.getModel().getElementAt(i).toString();
                       if(selState==true&&enableState[i]==false){
                         continue;
                    if(selState[i]==true&&enableState[i]==true){
                         if(val.length()==0){
                                   val=val+curString+"-1";
                         } else {                              
                                   val=val+"&"+curString+"-1";
                    if(selState[i]==false&&enableState[i]==true){
                         if(val.length()==0){
                                   val=val+curString+"-0";
                         } else {                              
                                   val=val+"&"+curString+"-0";
          return val;
     public void updateSelectionStateTrackers(JList list) {
          selState = new boolean[ list.getModel().getSize() ];
          enableState = new boolean[ list.getModel().getSize() ];
          for(int i = 0; i < selState.length; i++) {
               selState[i] = false;
               enableState[i] = true;
     public int[] getSelectedIndices() {
          if(!useCheckBoxAsIcon()) {
               return new int[0];
          int length = 0;
          if(selState==null){
               return null;
          for(int i = 0; i < selState.length; i++) {
               if(selState[i]) {
                    length++;
          int[] indices = new int[length];
          for(int i = 0, n = 0; i < selState.length; i++) {
               if(selState[i]) {
                    indices[n++] = i;
          //System.out.println("Selected Indices.length = " + indices.length);
          return indices;
     public Vector<Object> getSelectedObjects() {
          int[] indices = getSelectedIndices();
          Vector<Object> objects = new Vector<Object>();
          if(indices==null){
               return null;
          for(int i = 0; i < indices.length; i++) {
               objects.addElement( theList.getModel().getElementAt(indices[i]) );
          return objects;
     public void setIconHasBackground(boolean b) {
          useIconBackground = b;
     public Icon[] getIcons() {
          return icons;
     public Icon getIcon(int index) {
          if(icons != null && icons.length == 0) {
               return icon;
          if(icons != null && index > icons.length) {
               index = index - (icons.length - 1);
          return icons[index];
     public void setIcons(Icon[] icons) {
          if(icons != null) {
               useIndexSensitiveIcons = true;
          this.icons = icons;
     public void setIcon(Icon icon, int index) {
          if(icons != null && icons.length > 0) {
               icons[index] = icon;
     public void setIconLabelDimension(Dimension dim) {
          labelDim = dim;
     public static IconedCellRendererField getCheckBoxRendererInstance() {
          IconedCellRendererField cr = new IconedCellRendererField(new EmptyIcon());
               cr.setUseCheckBoxAsIcon(true);
          return cr;
     public void setUseCheckBoxAsIcon(boolean use) {
          useCheckBoxAsIcon = use;
          createNoBackgroundPanel();
     public boolean useCheckBoxAsIcon() {
          return useCheckBoxAsIcon;
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
     public void setDisplayItemsAsLinks(boolean use) {
          useLinkState = use;
     public void setLinkColor(Color color) {
          linkColor = color;
          if(theList != null) {
               theList.repaint();
     public Color getLinkColor() {
          return linkColor;
     public void setHoverLinkColor(Color color) {
          hoverColor = color;
          if(theList != null) {
               theList.repaint();
     public Color getHoverLinkColor() {
          return hoverColor;
     public void setSelectedLinkColor(Color color) {
          selectedLinkColor = color;
          if(theList != null) {
               theList.repaint();
     public Color getSelectedLinkColor() {
          return selectedLinkColor;
     public void attachLinkSimulationListener() {
          theList.setCursor( Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) );
          theList.addMouseListener( new MouseAdapter() {
               public void mouseEntered(MouseEvent e) {
                    isOnRow = true;                    
               public void mouseExited(MouseEvent e) {
                    isOnRow = false;
currentLinkRow = -1;
theList.repaint();
          theList.addMouseMotionListener( new MouseMotionAdapter() {
               public void mouseMoved(MouseEvent e) {
isOnRow = true;
currentLinkRow = theList.locationToIndex( e.getPoint() );
theList.repaint();
          /*table.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
public void mouseExited(MouseEvent e) {
isOnRow = false;
currentHighlightRow = -1;
table.repaint();
table.addMouseMotionListener( new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
isOnRow = true;
currentHighlightRow = table.rowAtPoint( e.getPoint() );
table.repaint();
     public boolean shdPaintDivider() {
          return paintDivider;
     public void setPaintDivider(boolean paintDivider) {
          this.paintDivider = paintDivider;
     public void setDividerImage(Icon icon) {
          this.dividerImage = icon;
          setPaintDivider(true);
     private void dispatchEvent(MouseEvent me) {
if(rect != null && box != null && rect.contains(me.getX(), me.getY())){
Point pt = me.getPoint();
pt.translate(0,0);
box.setBounds(rect);
box.dispatchEvent(new MouseEvent(box, me.getID()
, me.getWhen(), me.getModifiers()
, pt.x, pt.y, me.getClickCount()
, me.isPopupTrigger(), me.getButton()));
if(!box.isValid()) {
     repaint();
     System.out.println("Dispatch Event: Box.invalid called");
System.out.println("Dispatch Event called");
} else {
     System.out.println("Dispatch Event Called, rect null");
public void mouseClicked(MouseEvent me){
dispatchEvent(me);
public void mouseEntered(MouseEvent me){
dispatchEvent(me);
public void mouseExited(MouseEvent me){
dispatchEvent(me);
public void mousePressed(MouseEvent me){
dispatchEvent(me);
public void mouseReleased(MouseEvent me){
dispatchEvent(me);
public class SelectionStateHandler extends MouseAdapter {
     JList list = null;
     public SelectionStateHandler(JList list) {
          this.list = list;
     public void mouseClicked(MouseEvent e)
          * Handles the checkbox selection process. Uses the bounds property of the
          * check box within the selected cell to determine whether the checkbox should
          * be selected or not
          public void mouseReleased(MouseEvent e) {
               /*if(list == null || list.getSelectedIndex() == -1
     || !isEnabled( list.locationToIndex(e.getPoint()) ) ) {
     return;
          if(list == null || list.getSelectedIndex() == -1){
               return;
     int[] indices = list.getSelectedIndices();
     // get the current relative position of the check box
     //rect = box.getBounds(rect);
     for(int i = 0; i < indices.length; i++) {
     // get the current relative position of the check box
     int loc = list.locationToIndex( e.getPoint() );
     rect = list.getCellBounds(loc,loc);
     // ensure the point clicked in within the checkBox
     if(e.getX() < (rect.getX() + 20) ) {
          Object obj=list.getModel().getElementAt(i);
          //if(!obj.equals("SelectAll")&&!obj.equals("ClearAll")&&!obj.equals("GrayedAll")){
               if(indices[i]>2){
                    selState[0]=false;
                    selState[1]=false;
                    selState[2]=false;
                    //����
                    if(!this.isEnabled(indices[i])&&selState[indices[i]]==true){
                         this.setEnabled(indices[i],true);
                         selState[indices[i]]=false;
                    } else if(this.isEnabled(indices[i])&&selState[indices[i]]==true){
                         //����
                         selState[indices[i]]=true;
                         this.setEnabled(indices[i],false);                              
                    }else if(this.isEnabled(indices[i])&&selState[indices[i]]==false){
                         //����
                         selState[indices[i]]=true;
                         this.setEnabled(indices[i],true);
               } else {
                    selState[indices[i]] = !selState[indices[i]];
     list.revalidate();
     list.repaint();
     public void selectAll(boolean b) {
          for(int i = 0; i < list.getModel().getSize(); i++) {
               try {
                    this.enableAll(true);
                    Object obj=list.getModel().getElementAt(i);
                    if(!obj.equals("ClearAll")&&!obj.equals("GrayedAll")){
                         selState[i] = b;
                    } else{
                         selState[i]=!b;
                    selState[0]=false;
               } catch(ArrayIndexOutOfBoundsException aie) {
                    updateSelectionStateTrackers(list);
                    selectAll(b);
                    return;
          if(list != null) {
               list.revalidate();
               list.repaint();
     public void clearAll(boolean b){
          for(int i = 0; i < list.getModel().getSize(); i++) {
               try {
                    Object obj=list.getModel().getElementAt(i);
                    this.enableAll(true);
                    if(!obj.equals("ClearAll")){
                         selState[i] = !b;
                    } else{
                         selState[i]=b;
                    selState[1]=false;
               } catch(ArrayIndexOutOfBoundsException aie) {
                    updateSelectionStateTrackers(list);
                    selectAll(b);
                    return;
          if(list != null) {
               list.revalidate();
               list.repaint();
     public void grayedAll(boolean b){
          for(int i = 0; i < list.getModel().getSize(); i++) {
               try {
                    Object obj=list.getModel().getElementAt(i);
                    if(!obj.equals("SelectAll")&&!obj.equals("ClearAll")){
                         if(i==2){
                              selState[i] = !b;
                         }else{                             
                              selState[i] = b;
                         this.setEnabled(i,false);
                    } else{
                         selState[i]=!b;                          
               } catch(ArrayIndexOutOfBoundsException aie) {
                    updateSelectionStateTrackers(list);
                    selectAll(b);
                    return;
          if(list != null) {
               list.revalidate();
               list.repaint();
     public void setSelectedIndex(int index) {
          for(int i = 0; i < list.getModel().getSize(); i++) {
               selState[i] = false;
          selectIndex(index);
     public void selectIndex(int index) {
          try {
               selState[index] = true;
          } catch(ArrayIndexOutOfBoundsException aie) {
               updateSelectionStateTrackers(list);
               selectIndex(index);
               return;
          if(list != null) {
               list.revalidate();
               list.repaint();
     public void setEnabled(int index, boolean b) {
          try {
               enableState[index] = b;
          } catch(ArrayIndexOutOfBoundsException aie) {
               updateSelectionStateTrackers(list);
               setEnabled(index, b);
     public boolean isEnabled(int index) {
          if(index == -1) {
               return true;
          boolean isEnabled = true;
          try {
               isEnabled = enableState[index];
          } catch(ArrayIndexOutOfBoundsException aie) {
               updateSelectionStateTrackers(list);
               return isEnabled(index);
          return isEnabled;
     public void enableAll(boolean b) {
          for(int i = 0; i < enableState.length; i++) {
               enableState[i] = b;
public void selectAll(boolean b) {
     if(selStateHandler == null) {
          return;
     selStateHandler.selectAll(b);
public void clearAll(boolean b){
     if(selStateHandler == null) {
          return;
     selStateHandler.clearAll(b);
public void grayedAll(boolean b){
     if(selStateHandler == null) {
          return;
     selStateHandler.grayedAll(b);
public void setSelectedIndex(int index) {
     if(selStateHandler == null) {
          return;
     selStateHandler.setSelectedIndex(index);
public void selectIndex(int index) {
     if(selStateHandler == null) {
          return;
     selStateHandler.selectIndex(index);
public void enableAll(boolean b) {
     if(selStateHandler == null) {
          return;
     selStateHandler.enableAll(b);
public void setEnabled(int index, boolean enable) {
     if(selStateHandler == null) {
          return;
     selStateHandler.setEnabled(index, enable);
public boolean isEnabled(int index) {
     if(selStateHandler == null) {
          return true;
     return selStateHandler.isEnabled(index);
public boolean isEnabledAll() {
     if(enableState == null) return true;
     for(int i = 0; i < enableState.length; i++) {
          if(!isEnabled(i)) {
               return false;
     return true;
// EmptyIcon implementation
public static class EmptyIcon implements Icon {
     int width = 16, height = 16;
     public EmptyIcon() {
     setSize(16,16);
     public EmptyIcon(int width, int height) {
     setSize(width, height);
     public void setSize(int width, int height) {
     this.width = width;
     this.height = height;
     public int getIconWidth() {  return width; }
     public int getIconHeight() { return height; }
     public void paintIcon(Component c, Graphics g, int x, int y) {}
public int getItemCount(){
     if(theList!=null){
          return theList.getModel().getSize();
     } else {
          return 0;
     public boolean[] getEnableState() {
          return enableState;
     public boolean[] getSelState() {
          return selState;
     public JList getTheList() {
          return theList;
testbox :import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class testbox extends JComboBox
* @param args
JComboBox myComboBox;
public testbox()
myComboBox = new JComboBox();
public void setPopupVisible(boolean b)
     if(b)
          myComboBox.showPopup();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

You are updating the label value when (index == -1), let change into (index<=0).
like below
// this should cause a JComboBox to paint the Label instead of the
            // check box + label combination
            if (index <= 0) {
                Vector v = new Vector();
                v = getSelectedObjects();
                String val = generateString();
                JLabel label = new JLabel(val);
                if (iconLabel.getIcon() != null) {
                    label.setIcon(iconLabel.getIcon());
                System.out.println("label");
                return label;
            }

Similar Messages

  • Update JComboBox items

    Hi forum
    I want a JComboBox which items could be updated by code (with my "update" method) or when an item is changed by the user.
    So, its items would be updated when the user change its selection or when the "update" method is invoqued externly.
    Before I used an ActionListener, but now I think that it's better to use a FocusListener to only attend the user interactions.
    I tried to to make an example, but I got an infinite loop. Below is the code.
    I apreciate any solution.
    Thanks a lot.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JComboBoxProblem extends JFrame {
         private String[] modelos = new String[] {"Ferrari", "Porche", "BMW", "Lamborgini"};
         private JComboBox combo = new JComboBox(this.modelos);
         private JLabel label = new JLabel();
         public JComboBoxProblem() {
              super();
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(150,80);
              this.setLocation(300,200);
              this.setLayout(new GridLayout(2,1));
              this.add(BorderLayout.CENTER,this.label);
              this.add(BorderLayout.SOUTH,this.combo);
              this.update();
              this.setVisible(true);
              this.combo.addFocusListener(new FocusAdapter() {
                   // si el JComboBox coje el foco (lo ha seleccionado el usuario)
                   public void focusGained(FocusEvent fe) {
                        combo.addItemListener(new ItemListener() {
                             public void itemStateChanged(ItemEvent ie) {
                                  if (ie.getStateChange()==ItemEvent.SELECTED) {
                                       update();
         private void update() {
              DefaultComboBoxModel m = (DefaultComboBoxModel)this.combo.getModel();
              Object o = m.getSelectedItem();
              m.removeAllElements();
              for (int i=0; i<this.modelos.length; i++) {
                   m.addElement(this.modelos);
              this.label.setText("coche n� "+ (m.getIndexOf(o)+1));
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        try {
                             new JComboBoxProblem();
                        } catch (Exception ex) {}
    Message was edited by:
    xcorpyon
    Message was edited by:
    xcorpyon

    Hi again
    I'll try to explain my problem with JComboBoxes again with a new sample.
    It begins when I have more than one JComboBoxes and specially when I want to change and update its selected item.
    In the following sample I don't understand for example why does the second combo update twice and the first combo once (you can see it executing the sample).
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JComboBoxProblem extends JFrame {
         private String[] modelos1 = new String[] {"Ferrari", "Porche", "BMW", "Lamborgini"};
         private String[] modelos2 = new String[] {"Boa", "Anaconda", "Pit�n"};
         private JComboBox combo1 = new JComboBox(this.modelos1);
         private JComboBox combo2 = new JComboBox(this.modelos2);
         private JLabel label = new JLabel();
         private int inc=0;
         public JComboBoxProblem() {
              super();
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(180,120);
              this.setLocation(300,200);
              this.setLayout(new GridLayout(3,1));
              this.add(this.label);
              this.add(this.combo1);
              this.add(this.combo2);
              this.update();
              this.setVisible(true);
              this.combo1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        update();
              this.combo2.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        update();
         private void update() {
              this.combo1.setModel(new DefaultComboBoxModel(this.modelos1));
              this.combo1.setSelectedIndex(1);
    //          this.combo2.setModel(new DefaultComboBoxModel(this.modelos2));
    //          this.combo2.setSelectedIndex(2);
              this.label.setText("updated "+ (++inc) +" times");
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        try {
                             new JComboBoxProblem();
                        } catch (Exception ex) {}
    }Thanks a lot

  • Unable to update JComboBox in JDialog

    Method configureShiftList() updates the contents of a JComboBox in one of my JDialogs however when the JDialog is then displayed the updated contents of the JComboBox are not displayed. Thoughts on how to change this?
    public class addButton3Handler implements  ActionListener {
      public void actionPerformed( ActionEvent e) {
        configureShiftList();
        addList3Dialog.validate();
        addList3Dialog.setVisible(true);     
    }

    Have you made sure that the container of this
    component is also validated. If the container is not
    validated, then the change that you've made here would
    not have shown up.
    V.V.Isn't the JDialog the container or are you saying I need to also validate the parent JPanel and/or its parent JFrame?
    Thanks,
    Vaughn

  • Patch Update - Disks lost labels

    Hi Gurus,
    I have a problem with solaris 10 update 3 where by disks lost labels after a patch update. Can you please help me figure out what might have gone wrong?
    Please be patient with me as i am still newbie to the Solaris OS.
    Thanks in advance

    There is no update from 10.2.8. You need to purchase retail version of Tiger, 10.4.x. It would help if you gave as much information about your Mac as possible; i.e., model, ram, hard drive, etc.....What method were you using to install the new OS?

  • How to update JComboBox automaticly

    Hi I need help
    I have a JComboBox which has month from Jan to Dec.
    How do I make the JComboBox to show the month from the databases Example I retreive data that has the January in it but the JComboBox is showing March how do I make JComboBox to show January automaticly
    Thank You

    JComboBox.setSelectedItem or setSelectedIndex depending on how it is set up in your database. Pass the method the value of the month from the database (remember Jan index will be 0 in combo box)

  • Is there an update that addresses the different rending in photos between Library & Dev modules?

    The changes that I have made in the Development module are not reflected in the rendering of the photo in the Library module.  Is there an update or guidance that addresses this difference in rendering?

    What differences are you seeing?
    There is a slight difference in the way sharpening and noise reduction are shown.  Briefly: in Develop Module, sharpening and noise reduction may not always be fully rendered except at 100% view (this, I understand, is to save rendering time - you can't judge sharpening and noise reduction except at 100% anyway).  They are shown in Library Module, as they need to be rendered only once between edits (and the rendering is saved in the previews).
    If you are seeing any other difference - especially a difference in colour - that may indicate a problem with your monitor profile. 
    Is your monitor calibrated and profiled - with a hardware tool (ColorMunki, Spyder etc)?

  • Update POWL tab label

    Hello,
    We are implementing SRM 7 stack 09 with EP 7.
    We changed several times the name of a query in POWL_QUERY.
    Depending when they connected users see different labels in Query tab in the portal ( SC POWL). Some see last name, others former name of the Query.
    How can we "refresh" the query name to make sure everybody sees the same label?
    I suppose this is in portal.
    Thanks in advance.

    Hi
    It does not seem to work.
    User can change POWL tab label in the "settings" of the Query. We are looking for a report that could align all users' settings.
    Thanks.

  • Updated list of label printers compatible with Multi-Order Shipping?

    The only lists I can find in here are are from threads that are 5+ years old. Does anybody have an updated list? Thanks in advance!

    The v10.51.2.0 driver is compatible with 10.7.2. I am using this version with my MG6150. And if you look at this link from the Canon Australia web site, you can see that they show this version 10.51.2.0 being released to add support of OS X 10.7.

  • Render and preview issues with Premiere CC 2014 update

    Rendering issues: Adobe Premiere Pro CC 2014.0.1 Update does not fix" Occasional instance where sequences could never finished rendering"
    It's been 3 days 3 technicians and still same issue. Everything has been tried except starting over which is not an option. Worked
    fine in CS6.  
    1. Optimization of windows and tweek premiere memory settings,
    2. GPU updates,
    3. Software only render,
    4.render section at a time works (but who has time for that),
    5. Tweek virtual memory, - clean cache, clean temp files,
    6. hardware considerations, drives, etc...
    7. Other
    Ceremony completed render except for export in older computer. Please fix issue or give money back until you do!
    The rendering of footage of:
    1. render worked (on complex Ceremony 19 min sequence with AVCHD format and HDV) in an old computer. - Core 2 DUO Quad 8 gb ram 2g
    b GPU
    2. Same sequence of Ceremony (19 min sequence with AVCHD format and HDV) did not work in the faster computer. - i7 QUAD core 16 ram
    1 or 2 GB GPU
    3. Reception sequence of HDV footage only did not on both computer.
    Please call the exterminator and get rid of all the bugs. I am spending more time
    troubleshooting than editing….and that is bad

    You really aren't reading what we write.
    Let's break it down:
    Suitcase isn't working with the new application versions, because Suitcase has bugs in it's code or just doesn't know about the new application versions.
    The only way to fix that is to fix the code for Suitcase.
    Suitcase is written by Extensis, so only Extensis can fix the code for Suitcase.
    So you are waiting on Extensis to fix their code to work correctly with the new applications.
    This is not about the CC 2014 applications, this is about Extensis code not working, and Extensis needing to provide an update to make their code work.
    To get a working version of Suitcase (which requires fixing bugs in Suitcase), you need to talk to Extensis.

  • Can't render background color in JComboBox, after selection.

    I don't understand why this problem is so difficult. It is driving me nuts.
    If I create a renderer for a Jcombobox, it will correctly render TEXT and COLOR if it is displaying it in the pop up list, but as soon as it has been selected, the combo will render TEXT correctly but will ignore COLOR. I have tried playing around with opacity and with the editors, but it just seems as if JComboBox renderers do not work 100% as expected.
    Here is my text code. All I want is for the color of X or Y to be reflected in the selected element :
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    public class CustomComboBoxDemo extends JPanel {
        public CustomComboBoxDemo() {
            super(new BorderLayout());
            String[] s = { "1", "2", "3", "4", "5" };
            JComboBox c = new JComboBox(s);
            JComboBox c2 = new JComboBox(s);
            c.setOpaque(true);
            ComboBoxRenderer renderer= new ComboBoxRenderer();
            c.setRenderer(renderer);
            c2.setRenderer(renderer);
            JPanel p = new JPanel();
            p.add(c);
            p.add(c2);
            add(p);
        class ComboBoxRenderer extends DefaultListCellRenderer {
            public ComboBoxRenderer() {
                setOpaque(true);
            public Component getListCellRendererComponent(
                                               JList list,
                                               Object value,
                                               int index,
                                               boolean isSelected,
                                               boolean cellHasFocus) {
                 JLabel c = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                 if (value.toString().equals("3")) {
                     c.setText("X");
                     c.setBackground(Color.RED);
                 } else {
                     c.setText("Y");
                     c.setBackground(Color.GREEN);
                 return this;
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("CustomComboBoxDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new CustomComboBoxDemo());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    }

    I think the problem has to do with the Alloy look and feel. If I use the Systsem look and feel then the setBackground() method does not colour in the button (just the textfield)
    This has fixed my initial problem :
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicComboBoxEditor;
    public class CustomComboBoxDemo extends JPanel {
        public CustomComboBoxDemo() {
            super(new BorderLayout());
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {
                   e.printStackTrace();
            String[] s = { "1", "2", "3", "4", "5" };
            JComboBox c = new JComboBox(s);
            JComboBox c2 = new JComboBox(s);
    //        c.setRenderer(aRenderer)
    //        c.getEditor().getEditorComponent().setBackground(Color.GREEN);
            c.setBackground(Color.pink);
            c2.setBackground(Color.pink);
    //        c2.setBackground(Color.black);
            c.setOpaque(true);
            c2.setOpaque(false);
            ComboBoxRenderer renderer= new ComboBoxRenderer();
            c.setRenderer(renderer);
            c2.setRenderer(renderer);
            JPanel p = new JPanel();
            p.add(c);
            p.add(c2);
            add(p);
        private class MyComboBoxEditor extends BasicComboBoxEditor{
             public Component getEditorComponent(){
                  Component comp = super.getEditorComponent();
                  comp.setBackground(Color.red);
                  return comp;
        class ComboBoxRenderer extends DefaultListCellRenderer {
            public ComboBoxRenderer() {
                setOpaque(true);
            public Component getListCellRendererComponent(
                                               JList list,
                                               Object value,
                                               int index,
                                               boolean isSelected,
                                               boolean cellHasFocus) {
                 JLabel c = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    //             setForeground(Color.green);
    //             setBackground(Color.black);
    //             list.setForeground(Color.green);
    //             list.setBackground(Color.black);
                 if (value.toString().equals("3")) {
                     c.setText("X");
                     c.setBackground(Color.RED);
                 } else {
                     c.setText("Y");
                     c.setBackground(Color.GREEN);
                 return this;
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("CustomComboBoxDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new CustomComboBoxDemo());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    }

  • Why does TS Operator Interface Resource file not update panel labels correctly?

    There seems to be a problem with TS1.0.2 with the retrieval of Resource strings. If there are other INI files in the Components\User\Language\English directory other than the "OperatorInterfaceStrings.ini" file, the default operator interface seems to randomly use other files when attempting to get the resource strings to update my panel labels. The problem occured when I created a copy of the original "copy*.ini" file and my OI kept using the text values from the old file even after closing the OI and restarting it. Would like to know why.

    Hi Todd,
    In the \User\Language\English directory should be a file called CustomStrings.ini.
    Put your additional Resource strings in this file and keep your default ini files unaltered in the \NI\.. folder.
    Follow the structure as per the default inis and as per the user manual.
    This should sort your problem out.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Rendered clips turned out to be not render after premiere pro update

    Hello guys,
    I was using the old version of premiere pro for quite awhile, then my colleague told me to update it to the lastest to fix any bugs that exist.
    so I updated my premiere pro to version 4.2.1.
    After the update, I realised all the rendered files became not render. the timelines were all red and the program did not prompt for the rendered clips when I open the projects. For what I know, the rendered clips are still in the folder 'Adobe Premiere Pro Preview Files.'
    I am really desperate for help as the amount of clips rendered is really a lot. I appreciate any help, thanks so much.

    Welcome to the forum.
    It sounds like the update might have separated the Render files from the Project's links.
    Now, remember that Rendering is only necessary for the smoothest playback. You only have to Render, where you are working with critical aspects, like Keyframing Motion/Scale, or adding Effects. I complete many Projects, and never bother to Render, as I can see playback at a high enough level to do my editing. OTOH, there are often tiny segments, that might get Rendered many dozens of times - usually where Keyframing was done.
    One can use the WAB (Work Area Bar) to just Render a small segment of the Timeline.
    Now, why your existing Render files became un-Linked, I do not know that answer.
    Good luck,
    Hunt

  • Update button label when locale changes, in AS3

    What I'm trying to do is pretty do what this does:
    <s:Button label="{resourceManager.getString('Strings', 'some_resource')}"/>
    but in ActionScript code. I have a function to add a new tab button to a layout which takes a string and just trying to set the label to the same string doesn't work obviously. So what I need is a way to set the button label to some bindable value that will update whenever the locale changes, like it does automatically when doing it in MXML.

    Nevermind, I figured it out. For those of you that are curious about the solution I found it's in the code below. The only way I could figure out how to get it working is by declaring a local function right after creating a button and attaching it as a "change" event handler to the resourceManager.
    public function addTab(resourceName:String):uint
         var newTab:Button = new Button();
         newTab.label = resourceManager.getString('Strings', resourceName);
         newTab.setStyle("skinClass", Skins.Buttons.TabButton);
         // Create a local function that will update the button label whenever the locale changes
         var localeChangeHandler:Function =
              function (e:Event):void
                   newTab.label = resourceManager.getString('Strings', resourceName);
         resourceManager.addEventListener("change", localeChangeHandler);

  • Update Indicator label during Run time

    Hi all,
    This is the situation, i have an Indicator to display Acceleration, Velocity & Displacement. I am using it a local variable in the 2 case structures. 
    Here is what i want to achieve:
    I want to update the Indicator label for the respective Radio Button control. If the click on Acceration button, the label should be updated to Acceleration during Run time. Correspondingly for Velocity and Displacement button. 
    Can anyone help me how to go about this.
    Excuse me if i am not clear about anything.
    Thanks in advance

    Generally you should not change the label of a control, because this is often how the control is referred to from elsewhere in the program and it causes confusion.
    Instead there is a Caption property. If you right click the control and select Visible Items->Caption, the label is hidden and the caption is displayed instead (with the same text).
    In your block diagram, right click on the chart terminal and select Create->Property Node->Caption->Text. This creates a property node for the caption property. You will need to click on it to change it to 'Write' rather than 'Read' - you can then wire whatever text string you like and it will update on the front panel.

  • Chinese font won't render in Android4.4/Air4.0 with StyleableTextField

    Updating our app for the Latest Android 4.4/Air 4.0 SDK. Our app is localized for several languages, including Chinese.
    Ther app renders Chinese fine on Android devices less than android version 4.4 compiled with Air SDK 4.0.
    But on android ver. 4.4 with Air SDK 3.9 or SDK 4.0 only, chinese text will not render using StyleableTextField in our item renderers.
    A regular spark Label WILL render the chinese font just fine with Android 4.4/SDK 3.9/4.0.
    The android 4.4 device we have tested on is a Nexus 7. We are not using an embedded font for chinese.
    On our Nexus 7, this problem *doesent* exist with Air SDK 3.7 used with Android 4.4, but does with Air SDK 3.9 or SDK4.0.
    So it appears the problem started with Air 3.9.
    I have included  screenshots for both cases to show what it looks like.
    Thanks for any help getting it fixed so we can support the latest android 4.4 devices along with Air SDK 4.0 for our Chinese customers.
    Android 4.4 / Air SDK 4.0 (Nexus 7)
    Android 4.4 / Air SDK 3.7 (Nexus 7)

    Hi,
    The issue is known to us and currently we are investigating on this.
    Thanks for reporting,
    Nimit

Maybe you are looking for