Radu Stejerean
Radu Stejerean

Reputation: 345

Edit item in Jlist

How can I edit an item from a Jlist by simply adding an integer after that specific item (something like an append) ? Adding items to jlist with addbuttonlistener work fine but I don't know how can I edit them .

Upvotes: 1

Views: 5142

Answers (3)

ManhNguyen
ManhNguyen

Reputation: 121

I think you can used

 int x = txtList.getSelectedIndex();
    if (x >= 0) {
        listModel.remove(x);
        txtList.setModel(listModel);
    }

txtlist is your jlist name. First, you should declare listmodel. if have problem , you can contact me to discus

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

You have to update the model object.

Upvotes: 2

Jonas
Jonas

Reputation: 128807

One solution is to use a JTable with a single column. Then you can use a CellEditor. See more about JTable and CellEditors on How to use Tables.

Upvotes: 4

Related Questions