The list of methods to do JList are organized into topic(s).
void
applyDefaultProperties(final JList> comp) Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
return;
applyProperties(comp, "List.background",
"List.foreground",
"List.font");
void
ensureCustomBackgroundStored(JList comp) ensure Custom Background Stored
if (getStoredBackground(comp) != null)
return;
Color background = comp.getBackground();
if ((background == null) || (background instanceof UIResource) || (background == WARNING_BACKGROUND)
|| (background == ERROR_BACKGROUND))
return;
comp.putClientProperty(STORED_BACKGROUND_KEY, background);
void
filterDataList(JList jList, List dataList, String text) filter Data List
jList.setListData(new Object[] {});
List newList = new ArrayList();
dataList.stream().filter((ob) -> (ob.toString().toLowerCase().startsWith(text.toLowerCase())))
.forEach((ob) -> {
newList.add(ob);
});
jList.setListData(newList.toArray());
int
indexList(JList list, Object object) index List
ListModel model = list.getModel();
if (model == null) {
model = new DefaultListModel();
list.setModel(model);
;
if (model instanceof DefaultListModel) {
DefaultListModel listModel = (DefaultListModel) model;
...
int
indexOf(JList jList, Object obj) index Of
ListModel model = jList.getModel();
int i;
for (i = model.getSize() - 1; i >= 0; i--)
if (model.getElementAt(i) == obj)
break;
return i;