0

I have a JList that is a set size (Dimensions) consisting of an array of Strings that a user initially specifies. The JList is nested inside of a ScrollPane for whenever the elements go beyond the scope of the dimensions. My problem is that if the JList only has, for example, 4 items and a users clicks on a spot below the last index, the last index is selected. My JList is initialized with a DefaultListModel, and has a CellRenderer making it a list of checkboxes. How do I get the JList to stop selecting the last item even when an element isn't clicked?

Edit: CellRenderer

Color background = null;
    Color foreground = null;
    setOpaque(true);
    setText(value.toString());
    if (isSelected) {
        setForeground(Color.red);
        setSelected(true);
        value = value.toString().substring(0, value.toString().length() - 1);
        setText(value.toString());
    } else {
        if (value.toString().endsWith("t")) {
            background = Color.white;
            foreground = Color.green;
            setSelected(true);
            setBackground(background);
            setForeground(foreground);
            value = value.toString().substring(0, value.toString().length() - 1);
            setText(value.toString());
        } else {
            background = Color.white;
            foreground = Color.blue;
            setSelected(false);
            setBackground(background);
            setForeground(foreground);
            value = value.toString().substring(0, value.toString().length() - 1);
            setText(value.toString());
        }
    }
    return this;
leppie
  • 115,091
  • 17
  • 196
  • 297

0 Answers0