java - How do I retrieve the component type used at a specific cell in a JTable? -
i've created jtable
columns contain variety of different components. last 5 columns either contain nothing (a defaulttablecellrenderer
no value) or jradiobutton
using custom renderer , editor. renderer creates , returns new radiobutton in cells need one, , want access these radio buttons panel class add them buttongroup
. using following piece of code wrote:
protected void setbuttongroups() { buttongroups = new arraylist<buttongroup>(); (int = 0; < tablemodel.getrowcount(); i++) { buttongroup currentgroup = new buttongroup(); (int j = 0; j < tablemodel.getcolumncount(); j++) { if (table.getcomponentat(i, j) != null) { currentgroup.add((jradiobutton)table.getcomponentat(i, j)); } } } buttongroups.add(currentgroup); } }
getcomponentat()
keeps returning null regardless of contained in cell, whether jcheckbox
, jradiobutton
, jcombobox
... returned null.
is there alternative way cell's component? or there way me work? thank you!
if have tablemodel table.getmodel(). can call model.getvalueat(row,col)
i not sure why putting swing components inside jtable. using formatting? if look layoutmanagers. if want edit values in table, might want extending tablecelleditor. if want put components in table. consider extending defaulttablecellrenderer return component. want override gettablecellrenderercomponent().
Comments
Post a Comment