Monday, 15 September 2014

swing - Double click listener on JTable in Java -



swing - Double click listener on JTable in Java -

i curious how phone call valuechanged overridden method if row in jtable has been double clicked. below code snippet achieves 1 click action or event arrow key navigate through list of people , adjust jlabel accordingly. i'm trying similar did 1 click, time if , if row has been double clicked dto alter else nil happens. how do :(

class listdataui { public void addlistselectionlistener(listselectionlistener listselectionlistener) { summarytable.getselectionmodel().addlistselectionlistener(listselectionlistener); public t getselecteddto() { final int selectedrowindex = summarytable.getselectedrow(); if (selectedrowindex != -1) { homecoming data.get(summarytable.convertrowindextomodel(selectedrowindex)); } else { homecoming null; } } } } class mainmenu extends javax.swing.jframe { private void initlisteners() { searchtable.addlistselectionlistener(new listselectionlistener() { @override public void valuechanged(listselectionevent e) { if (!e.getvalueisadjusting()) { academicdto dto = (academicdto) searchtable.getselecteddto(); acimglabel.seticon(new imageicon()); label_name.settext(dto.gettitle() + " " + dto.getforename() + " " + dto.getsurname()); label_role.settext("role: " + dto.getrole()); label_phone.settext("phone: " + dto.getphone()); label_room.settext("room: " + dto.getroom()); label_hours.settext("hours: " + dto.gethours()); label_mobile.settext("mobile: " + dto.getmobile()); if (dto.getimage() != null) { acimglabel.seticon(new imageicon(dto.getimage())); } } } }); } } private void initlisteners() { contacttable.addmouselistener(new mouseadapter() { @override public void mouseclicked(mouseevent e) { contactdto dto = (contactdto) contacttable.getselecteddto(); if (e.getclickcount() == 2) { system.out.println(dto.getforename()); } else { } } }); }

not sure of rest above...

try this:

mytable.addmouselistener(new mouseadapter() { public void mousepressed(mouseevent me) { jtable table =(jtable) me.getsource(); point p = me.getpoint(); int row = table.rowatpoint(p); if (me.getclickcount() == 2) { // valuechanged overridden method } } });

java swing jtable double-click listselectionlistener

No comments:

Post a Comment