java - Disable popup menu on a JTable -
i creating table popop menu
jtable table = new table() table.addmouselistener( new mouseadapter() { public void mousereleased(mouseevent e) { if (e.ispopuptrigger()) { jtable source = (jtable)e.getsource(); int row = source.rowatpoint( e.getpoint() ); int column = source.columnatpoint( e.getpoint() ); if (! source.isrowselected(row)) source.changeselection(row, column, false, false); popup.show(e.getcomponent(), e.getx(), e.gety()); } } });
i want able enable/disable menu call, tried this:
table.setenabled(false)
but menu still pops up.. call should do?
you have boolean inside of class creating table called tablemenuenabled. should able set tablemenuenabled true or false planning on calling table.setenabled(false). there code change to:
table.addmouselistener( new mouseadapter() { public void mousereleased(mouseevent e) { if (tablemenuenabled && e.ispopuptrigger()) { jtable source = (jtable)e.getsource(); int row = source.rowatpoint( e.getpoint() ); int column = source.columnatpoint( e.getpoint() ); if (! source.isrowselected(row)) source.changeselection(row, column, false, false); popup.show(e.getcomponent(), e.getx(), e.gety()); } } });
Comments
Post a Comment