swing - Java- add an editable row to a JTable -
i have java gui displays jtable , button. when button clicked, want add new editable row of cells table. trying using following actionlistener()
, have assigned button:
addbtn.addactionlistener(new actionlistener(){ public void actionperformed(actionevent e){ system.out.println("'add' button pressed. "); defaulttablemodel model = (defaulttablemodel)jentityfiltertable.getmodel(); model.addrow(new object[]{"site", "application", "entity"}); system.out.println("--- actionlistener added 'addbtn' ---"); } });
in console, when click button, see message stating "'add' button pressed. "... however, exception says:
exception in thread "awt-eventqueue-0" java.lang.arrayindexoutofboundsexception: 0 >= 0
i assume occurring on model.addrow...
line, since place i've used array, i'm not sure why i'm getting error- i'm creating empty object array, , not defining size, surely shouldn't have problem index no matter how many elements add it- it's array dynamic size.
can point out i'm going wrong here?
edit 27/06/2014 @ 09:50
i've tried changing method slightly, have following code:
addbtn.addactionlistener(new actionlistener(){ public void actionperformed(actionevent e){ system.out.println("'add' button pressed. "); defaulttablemodel model = (defaulttablemodel)jentityfiltertable.getmodel(); vector<string> row = new vector<string>(); row.add("site"); row.add("application"); row.add("entity"); system.out.println("row count: " + model.getrowcount()); system.out.println("1st column: " + model.getcolumnname(0)); system.out.println("column count: " + model.getcolumncount()); model.addrow(row); system.out.println("--- actionlistener added 'addbtn' ---"); } });
when run application, , click button i've added actionlistener()
, see following output in console:
'add' button pressed.
row count: 0
1st column: site
column count: 3
exception in thread "awt-eventqueue-0" java.lang.arrayindexoutofboundsexception: 0 >= 0
it appear exception occurring on line:
model.addrow(row);
i can't work out why i'm getting exception on line- looks correct me... have ideas?
Comments
Post a Comment