java - JTable.setDefaultEditor() not working but setting to a specific field works. -


attempting use jtable.setdefaulteditor() doesn't seem activate. setting column works not setting default editor. println command not returned visible when setting specific column.

is there step required when setting default editor?

    import java.awt.*;     import javax.swing.*;     import javax.swing.table.tablecelleditor;     import javax.swing.table.tablecolumn;      public class main {       public static void main(string[] argv) throws exception {          jframe myframe = new jframe();         myframe.setdefaultcloseoperation(jframe.exit_on_close);         string columnnames[] = { "column 1", "column 2", "column 3" };          string datavalues[][] =         {                 { "12", "234", "67" },                 { "-123", "43", "853" },                 { "93", "89.2", "109" },                 { "279", "9033", "3092" }             };         jtable table = new jtable(datavalues, columnnames);         myframe.getcontentpane().add(table);          table.setdefaulteditor(string.class, new mytablecelleditor());     //    tablecolumn col = table.getcolumnmodel().getcolumn(0);     //    col.setcelleditor(new mytablecelleditor());         myframe.pack();         myframe.setvisible(true);       }     }      class mytablecelleditor extends abstractcelleditor implements tablecelleditor, focuslistener     {          jcomponent component = new jtextfield();          public mytablecelleditor()         {              component.addfocuslistener(this);           }        public component gettablecelleditorcomponent(jtable table, object value, boolean isselected,           int rowindex, int vcolindex) {           system.out.println("inside gettablecelleditorcomponent()");         ((jtextfield) component).settext((string) value);          return component;       }        public object getcelleditorvalue() {         return ((jtextfield) component).gettext();       }          @override         public void focusgained(focusevent e) {             // todo auto-generated method stub         }          @override         public void focuslost(focusevent e) {             system.out.println("focus lost");          }     } 

this 1 of reasons don't defaulttablemodel...

if change table.setdefaulteditor(string.class, new mytablecelleditor()); table.setdefaulteditor(object.class, new mytablecelleditor());, work, however, better solution override getcolumnclass method of defaulttablemodel

defaulttablemodel model = new defaulttablemodel(datavalues, columnnames){      @override     public class<?> getcolumnclass(int columnindex) {         // should checking columnindex ,         // returning appropriate data type column,         // idea         return string.class;     }  }; jtable table = new jtable(model); myframe.getcontentpane().add(table);  table.setdefaulteditor(string.class, new mytablecelleditor()); 

take @ how use tables more details


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -