java - Need to launch a new JPanel on click event in a JTable cell. -


i want create jtable having last column advanced options icon. on clicking last column in jtable, want new jpanel pop allowing user enter input required 4 string input fields. jpanel when dismissed, should return original jtable.

i not sure save data 4 fields new jpanel. 4 string input fields per jtable row, displayed in jpanel.

can jtabel cell hold object saving data?

usecase: have jtable 10 columns. getting cluttered want move 5 columns new panel launched on clicking advanced options icon in original jtable last column.

sample code on how associate data jpanel row in jtable highly appreciated.

in order show pop-up when cell clicked, need cell editor class. main purpose of class provide custom editors cells, can use trigger action when cell clicked:

public class infocelleditor extends abstractcelleditor implements tablecelleditor {      @override     public java.awt.component gettablecelleditorcomponent(jtable table, object value, boolean isselected, int row, int column) {         infoobject info = (infoobject) value;         editbutton = new jbutton(new infoaction(info));         editbutton.settext("info");         editbutton.setenabled(true);     }      private class infoaction extends abstractaction {          infoobject info;          public infoaction(infoobject info) {             super();             this.info = info;         }          public void actionperformed(actionevent e) {             joptionpane.showmessagedialog(null, info.tostring());             stopcellediting();         }     } } 

then, extend jtable class , implement getcolumnclass , iscelleditable methods:

public class mytable extends jtable {      public mytable() {         super();         setdefaulteditor(infoobject.class, new infocelleditor());     }      @override     public class getcolumnclass(int columnindex) {         if(columnindex == 4)             return infoobject.class;         else             return string.class;     }      @override     public boolean iscelleditable(int row, int column) {         if(column == 4)             return true;         else             return false;     } } 

lastly, should make sure infoobject instances inserted 5th column. , can implement tablecellrenderer custom visual representation of column.

object headers = new object[column_count]; object cells[][] = new object[row_count][]; ... cells[0][4] = new infoobject(data[0]); cells[1][4] = new infoobject(data[1]); table.setmodel(new defaulttablemodel(cells, headers)); table.getmodel().firetabledatachanged(); table.setvisible(); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -