java - Adding a JButton into a JTable which uses abstract table model -


i trying add jbutton first column on table created. did make research , couldn't find solution tables use abstract table model.

here, create object array each record has texts , boolean variables have table render check boxes. object arrays saved arraylist

here's code create table data.

public arraylist<object[]> settabledata(){          /*         * iteminfo fields         **********************         * line[0] - referenceno         * line[1] - quantity         * line[2] - itemnamedescriptionsku         * line[3] - cube         */          //setting data table         arraylist<object[]> itemlist = new arraylist<>();         (int i=0; i<this.iteminfo.size();i++){             object[] temparray = new object[7];             temparray[0] = this.iteminfo.get(i)[1]; //quantity             temparray[1] = this.iteminfo.get(i)[2].touppercase(); //item description             temparray[2] = this.iteminfo.get(i)[3]; //cube             //this adds charges if payment type cod             //to not write charge amount every row             //checks cod type @ first record of items             if (i==0 && this.invoice[8].equals("cod"))                 temparray[3] = this.invoice[22]; //charges if invoice type cod, null otherwise             else                  temparray[3] = " ";              temparray[4] = new boolean (false); //loaded             temparray[5] = new boolean (false); //delivered (will ignored if pickup)              itemlist.add(temparray);         }         return itemlist; 

here's table model

import java.util.arraylist; import javax.swing.table.abstracttablemodel;  public class tickettablemodel extends abstracttablemodel {      private arraylist<object[]> data;     private boolean isdelivery;     private string[] columns;       public tickettablemodel(arraylist<object[]> iteminfo, boolean isdelivery){         super();         this.data = iteminfo;         this.isdelivery = isdelivery;     }     @override     public string getcolumnname(int i) {          return this.columns[i];     }     public void setcolumns ( string[] columns1 ){         this.columns = columns1;     }      @override     public int getrowcount() {         return data.size();     }      @override     public int getcolumncount() {         return columns.length;     }     @override     public class getcolumnclass(int c) {         return getvalueat(0, c).getclass();     }      @override     public boolean iscelleditable(int row, int col) {         if (col < 3)             return false;         else              return true;     }      @override     public void setvalueat(object value, int row, int col) {         data.get(row)[col] = value;         firetablecellupdated(row, col);     }     @override     public object getvalueat(int row, int col) {          return this.data.get(row)[col];     } 

take @ table button column.

this class implements render/editor needed make button functional. provide action invoke when button pressed.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -