This is my current attempt
JButton btnNewButton_1 = new JButton("Remove Selected Shape");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultListModel<Node> model = (DefaultListModel<Node>)itemList.getModel();
Node selectedShape = itemList.getSelectedValue();
model.removeElement(selectedShape);
updateList();
}
});
I think I had a better approach before, but can not remember.
This is how my list is displayed
JList<Node> itemList = new JList<Node>(model);
scrollPane_1.setViewportView(itemList);
I have these initialized in my class
private JFrame frame;
private NodePlot plot;
JList<Node> itemList;
JScrollPane scrollPane;
private DefaultListModel<Node> model = new DefaultListModel<Node>();