Java Utililty Methods JList

List of utility methods to do JList

Description

The list of methods to do JList are organized into topic(s).

Method

voidapplyDefaultProperties(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"); 
voidclearList(JList list)
fillList
setListModel(generateListModel(), list);
voidensureCustomBackgroundStored(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);
voidensureRangeIsVisible(JList list, int top, int bottom)
ensure Range Is Visible
int size = list.getModel().getSize();
if (top < 0) {
    top = 0;
if (bottom >= size) {
    bottom = size - 1;
Rectangle cellBounds = list.getCellBounds(top, bottom);
...
voidfilterDataList(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());
ColorgetStoredBackground(JList comp)
get Stored Background
return (Color) comp.getClientProperty(STORED_BACKGROUND_KEY);
intgetVisibleRowCount(JList list)
get Visible Row Count
return list.getLastVisibleIndex() - list.getFirstVisibleIndex() + 1;
intindexList(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;
...
intindexOf(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;
booleanisDoubleClick(MouseEvent evt, JList lst, JButton btn)
Enable the associated button if single click.
if (lst.getMinSelectionIndex() >= 0) {
    switch (evt.getClickCount()) {
    case 1:
        btn.setEnabled(true);
        break;
    case 2:
        if (btn.isEnabled()) {
            return true;
...