java - JComponent contains method does not work in the MouseEvent action of JTable -
i have cell in jtable
jpanel
has located in it. jpanel
has 2 labels inside it. want different action when left label clicked, , want make operation when right action clicked. not want use tablecelleditor
, makes code complicated. becase cell values has range of type.
i write following code selected component mouse event, no success. tried swingutilies.convertmouseevent
, did not change anything. problem below code? why jcomponent
contains method not check mouse point.
contsimtable.addmouselistener(new mouseadapter() { public void mouseclicked(final mouseevent event) { if (swingutilities.isleftmousebutton(event)) { if (event.getclickcount() == 2) { jtable target = (jtable) event.getsource(); int row = contsimtable.getselectedrow(); int column = contsimtable.getselectedcolumn(); /** * convert view colum model.it column index * stored in table model */ int modelcolumn = target.convertcolumnindextomodel(column); object clickedcell = contsimtable.getvalueat(row, modelcolumn); if (clickedcell instanceof jpanel) { boolean issecond = false; jlabel = (jlabel) ((jpanel) clickedcell) .getcomponent(0); jlabel b = (jlabel) ((jpanel) clickedcell) .getcomponent(1); if (a.contains(event.getpoint())) { issecond = false; } // if (b.contains(event.getpoint())) { issecond = true; } } } } } });
a tablecelleditor
correct approach. there number of ways address different data types:
by default, discussed here.
by
tablecolumn
, shown here.by type-token returned
getcolumnclass()
, shown here.by overriding
getcelleditor()
, shown here.
for more specific guidance, please edit question include sscce typifies chosen approach.
Comments
Post a Comment