Yoh Hendry
Yoh Hendry

Reputation: 427

JTable programmatically update cell n retain cell selection

i have a problem that i met while playing around with JTable.
so here is the situation.
one of the cell has an integer 10,000,000 value (with the comas). and i wanted the cell to be able to update it to 10000000 (removing the comas) when i started editing it both by double clicking and typing directly.
i have tried around using setValueAt(), stopEditing(), removing cellEditor, setValueAt() from model as well as from casting to defaultTableModel, etc. but none work out.
I hope i can find some help from here. Thank you in advance. =]

Upvotes: 1

Views: 192

Answers (1)

Yoh Hendry
Yoh Hendry

Reputation: 427

thank you for the reply. i do found my own answer already. here goes.

((JTextField.AccessibleJTextComponent)itemTable.getEditorComponent().getAccessibleContext().getAccessibleComponent()).setTextContents(String.valueOf(itemTable.getValueAt(row, column)).replaceAll(",", ""));

Upvotes: 0

Related Questions