jcombobox - sorting java combobox items -


i'm trying names , ids database , add them combobox. i've added checkcombobox project;

http://chianti.ucsd.edu/svn/csplugins/trunk/soc/jgao/idmapping/src/csplugins/id/mapping/ui/checkcombobox.java

by of code; https://stackoverflow.com/a/17097767

            resultset resultset= "here getting result set query having order clause                 while (resultset.next()) {                 int id = resultset.getint(1);                 string name = resultset.getstring(2);                 system.out.println(name);                 options.add(new option<integer>(name, id));             } 

system.out.println gives output sorted name items in checkcombobox not sorted. how can add items sorted in combobox?

  1. don't use set constructor, use checkcombobox(map<object, boolean> mapobjselected) constructor.
  2. use treemap. set constructor creates linkedhashmap default, doesn't preserve order.
  3. properly implement compareto method in code option. may need add field tell options order they're supposed in.

Comments