0

I have a Jtable that gets filled with Strings. In a certain editable column, the user is able to modify the data diplayed and then saved. I want to know if there is a way to allow the user to only type certain strings in that cell, while keeping it blank even if he is typing in case the string typed is not allowed.

What i thought of is letting the user type whatever he wants then after he moves to another cell read what he typed and then match it with the strings I allow, to see if I accepted or pop up a warning window then empty the cell again. But I'm asking to se it there is anything more practical

Majd
  • 3
  • 3
  • 2
    Consider placing a `JComboBox` inside the table. [This question](http://stackoverflow.com/questions/457463/putting-jcombobox-into-jtable) might help – bradimus Aug 17 '16 at 13:56
  • if you dont want to use a `JComboBox` suggested from bradismus you might consider using the `TableModelListener` [Link](https://tips4java.wordpress.com/2009/06/07/table-cell-listener/) – mayha Aug 17 '16 at 14:04
  • 2
    A combo box is the best solution for a limited number of strings. If for some reason it doesn't meet your requirement then you can create a custom editor to do all the editing of the string value. A simple example is demonstrated in: http://stackoverflow.com/questions/20390445/swing-catching-exceptions-from-tablemodel/20390486#20390486 – camickr Aug 17 '16 at 14:56

0 Answers0