public static <T>void addFirstItem(JComboBox<T> combobox,T item){
  int idx=-1;
  DefaultComboBoxModel<T> model=(DefaultComboBoxModel<T>)combobox.getModel();
  for (int i=0; i < model.getSize(); i++) {
    T t=model.getElementAt(i);
    if (Objects.equals(t,item)) {
      idx=i;
      break;
    }
  }
  model.insertElementAt(item,0);
  if (idx >= 0) {
    model.removeElementAt(idx + 1);
  }
}

public static < T > void addFirstItem ( JComboBox < T > combobox , T item ) { int idx = - 1 ; DefaultComboBoxModel < T > model = ( DefaultComboBoxModel < T > ) combobox . getModel ( ) ; for ( int i = 0 ; i < model . getSize ( ) ; i ++ ) { T t = model . getElementAt ( i ) ; if ( Objects . equals ( t , item ) ) { idx = i ; break ; } } model . insertElementAt ( item , 0 ) ; if ( idx >= 0 ) { model . removeElementAt ( idx + 1 ) ; } }
checks if the item is in the combobox . if yes , then it is moved to the beginning , otherwise , the item is added as first .
