jcombobox - sorting java combobox items -
i'm trying names , ids database , add them combobox. i've added checkcombobox project;
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?
- don't use
set
constructor, usecheckcombobox(map<object, boolean> mapobjselected)
constructor. - use
treemap
.set
constructor createslinkedhashmap
default, doesn't preserve order. - properly implement
compareto
method in codeoption
. may need add field telloption
s order they're supposed in.
Comments
Post a Comment