That method, removeElement(...)
is part of the DefaultListModel, not the JList. You need to first call getModel()
on the JList, cast it to the DefaultListModel (after first checking that it is this type) and then call the method.
e.g.,
ListModel model = list.getModel();
if (model instanceof DefaultListModel && list.getSelectedValue() != null) {
((DefaultListModel) model).removeElement(list.getSelectedValue());
}
Relevant API entries:
solved Trying to call jlist method method removeelement getting error saying method is undefined