문제

I have a Jlist with a DefaultListModel with data from XML.

I want to be able change the name of the item in the Jlist. but the DefaultListModel has no update method.

So if the user clicks on a name it should edit the name.

So far I thought if I get the location of the item and remove it and update with new data. But if I update with then new name will it be put in the same location as the old or will things be messed up ?

My code :

private class EditName extends AbstractAction {
        public EditName() {
            putValue(NAME, "Change Name");
            putValue(SHORT_DESCRIPTION, "Some short description");
        }

        public void actionPerformed(ActionEvent e) {

             int x = objTypeJList.getSelectedIndex();
               String newName = JOptionPane.showInputDialog("New Name?");

                 if (x >= 0) {
                   String oldName = ReadXMLFile.getInstance().getModel().getElementAt(x).toString();
                   ReadXMLFile.getInstance().getModel().removeElementAt(x);
                   objTypeJList.setModel(ReadXMLFile.getInstance().getModel());
                }
                    // newText I wanna add into the the location I edit
            }

    }
도움이 되었습니까?

해결책

"I want to be able change the name of the item in the Jlist. but the DefaultListModel has no update method."

What makes you say that? Have you looked carefully at the docs ?

What do you think this method does?

OR

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top