java - JTable setting a default editor for a custom class -


i having issue trying set default jtable cell editor custom class. have several custom columns (numbers, strings , booleans). number types use own cell editors , boolean , string types wanted use default ones provided jtable class.

i have following code in setup of table:

jtable table; .... table.setdefaulteditor(myboolean.class, table.getdefaulteditor(boolean.class)); table.setdefaultrenderer(myboolean.class, table.getdefaultrenderer(boolean.class)); table.setdefaulteditor(mystring.class, table.getdefaulteditor(string.class); table.setdefaultrenderer(mystring.class, table.getdefaultrenderer(string.class); 

the boolean type works expected , can click on tickbox , have turn on , off. string type displays not let me edit. in model have columns return true editable.

if add following model:

@override public class<?> getcolumnclass(int columnindex){     class<?> clz = columns.get(columnindex).getclass();     if(clz.isassignablefrom(mystring.class)){         return string.class;     }     return clz; } 

i can edit strings expected.

my question: why setting default editor not work string class boolean class? why have have special case in getcolumnclass method in model?

assuming extending defaulttablemodel, note getcolumnclass(), inherited abstracttablemodel, "returns object.class regardless of columnindex." noted here, object "is rendered label displays object's string value." there no default editor object. in particular, "to specify more precise column types, table model must define getcolumnclass() method appropriately."


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -