ui/src/main/java/ucar/util/prefs/ui/ComboBox.java
public List<Object> getItemList() {
    ArrayList<Object> list = new ArrayList<Object>();
    for (int i=0; i< getItemCount() && i < nkeep; i++)
      list.add( getItemAt(i));
    return list;
  }

  /**
   * Use this to set the list of items.
   * @param list of items, may be any Object type.
   */
  public void setItemList(Collection<Object> list) {
    if (list == null) return;
    setModel( new DefaultComboBoxModel( list.toArray()));

    if (list.size() > 0)
      setSelectedIndex(0);
  }

  /** Set the number of items to keep */
  public void setNkeep( int nkeep) { this.nkeep = nkeep; }
  /** Get the number of items to keep */
  public int getNkeep() { return nkeep; }

  /** Get value from Store, will be an ArrayList or null */
  protected Object getStoreValue(Object defValue) {
    if (prefs == null)
      return defValue;
    return ((PreferencesExt)prefs).getBean(LIST, defValue);
  }

  /** Put new value into Store, must be a List of Strings */
  protected void setStoreValue(List newValue) {
    if (prefs != null)
      prefs.putList(LIST, newValue);
  }

  // debug
  private static long lastEvent;
  public static void main(String args[]) throws IOException {

    JFrame frame = new JFrame("Test");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    final ComboBox cb = new ComboBox( null);
    cb.addActionListener(e -> {
        System.out.println("**** cb event="+e);
        if (e.getActionCommand().equals("comboBoxChanged")) {
          //System.out.println("cb.getSelectedItem="+cb.getSelectedItem());
          cb.addItem( cb.getSelectedItem());
        }
    });
    cb.getEditor().getEditorComponent().setForeground(Color.red);

    /* JButton butt = new JButton("accept");
   butt.addActionListener( new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("butt accept");
        cb.accept();
     }
   }); */

    JPanel main = new JPanel();
    main.add(cb);
    // main.add(butt);

    frame.getContentPane().add(main);
    // cb.setPreferredSize(new java.awt.Dimension(500, 200));

    frame.pack();
    frame.setLocation(300, 300);
    frame.setVisible(true);
  }

}
public List<Object> getItemList() {
    ArrayList<Object> list = new ArrayList<Object>();
    for (int i=0; i< getItemCount() && i < nkeep; i++)
      list.add( getItemAt(i));
    return list;
  }

  /**
   * Use this to set the list of items.
   * @param list of items, may be any Object type.
   */
  public void setItemList(Collection<Object> list) {
    if (list == null) return;
    setModel( new DefaultComboBoxModel( list.toArray()));

    if (list.size() > 0)
      setSelectedIndex(0);
  }

  /** Set the number of items to keep */
  public void setNkeep( int nkeep) { this.nkeep = nkeep; }
  /** Get the number of items to keep */
  public int getNkeep() { return nkeep; }

  /** Get value from Store, will be an ArrayList or null */
  protected Object getStoreValue(Object defValue) {
    if (prefs == null)
      return defValue;
    return ((PreferencesExt)prefs).getBean(LIST, defValue);
  }

  /** Put new value into Store, must be a List of Strings */
  protected void setStoreValue(List newValue) {
    if (prefs != null)
      prefs.putList(LIST, newValue);
  }

  // debug
  private static long lastEvent;
  public static void main(String args[]) throws IOException {

    JFrame frame = new JFrame("Test");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    final ComboBox cb = new ComboBox( null);
    cb.addActionListener(e -> {
        System.out.println("**** cb event="+e);
        if (e.getActionCommand().equals("comboBoxChanged")) {
          //System.out.println("cb.getSelectedItem="+cb.getSelectedItem());
          cb.addItem( cb.getSelectedItem());
        }
    });
    cb.getEditor().getEditorComponent().setForeground(Color.red);

    /* JButton butt = new JButton("accept");
   butt.addActionListener( new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("butt accept");
        cb.accept();
     }
   }); */

    JPanel main = new JPanel();
    main.add(cb);
    // main.add(butt);

    frame.getContentPane().add(main);
    // cb.setPreferredSize(new java.awt.Dimension(500, 200));

    frame.pack();
    frame.setLocation(300, 300);
    frame.setVisible(true);
  }

}
public List < Object > getItemList ( ) { ArrayList < Object > list = new ArrayList < Object > ( ) ; for ( int i = 0 ; i < getItemCount ( ) && i < nkeep ; i ++ ) list . ( getItemAt ( i ) ) ; return list ; } /**
   * Use this to set the list of items.
   * @param list of items, may be any Object type.
   */ public void setItemList ( Collection < Object > list ) { if ( list == null ) return ; setModel ( new DefaultComboBoxModel ( list . toArray ( ) ) ) ; if ( list . size ( ) > 0 ) setSelectedIndex ( 0 ) ; } /** Set the number of items to keep */ public void setNkeep ( int nkeep ) { this . nkeep = nkeep ; } /** Get the number of items to keep */ public int getNkeep ( ) { return nkeep ; } /** Get value from Store, will be an ArrayList or null */ protected Object getStoreValue ( Object defValue ) { if ( prefs == null ) return defValue ; return ( ( PreferencesExt ) prefs ) . getBean ( LIST , defValue ) ; } /** Put new value into Store, must be a List of Strings */ protected void setStoreValue ( List newValue ) { if ( prefs != null ) prefs . putList ( LIST , newValue ) ; } // debug
 private static long lastEvent ; public static void main ( String args [ ] ) throws IOException { JFrame frame = new JFrame ( "Test" ) ; frame . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { System . exit ( 0 ) ; } } ) ; final ComboBox cb = new ComboBox ( null ) ; cb . addActionListener ( e -> { System . out . println ( "**** cb event=" + e ) ; if ( e . getActionCommand ( ) . equals ( "comboBoxChanged" ) ) { //System.out.println("cb.getSelectedItem="+cb.getSelectedItem());
 cb . addItem ( cb . getSelectedItem ( ) ) ; } } ) ; cb . getEditor ( ) . getEditorComponent ( ) . setForeground ( Color . red ) ; /* JButton butt = new JButton("accept");
   butt.addActionListener( new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("butt accept");
        cb.accept();
     }
   }); */ JPanel main = new JPanel ( ) ; main . add ( cb ) ; // main.add(butt);
 frame . getContentPane ( ) . add ( main ) ; // cb.setPreferredSize(new java.awt.Dimension(500, 200));
 frame . pack ( ) ; frame . setLocation ( 300 , 300 ) ; frame . setVisible ( true ) ; } }
Use this to obtain the list of items.
@return ArrayList of items, may be any Object type.
Use this to obtain the list of items .