java - Easy way to get the data from selected columns in JTable -


i have jtable , want data each selected column. columns selected mouse clicks. so, if there 5 columns selected, output has 5 string arrays.

i'm trying mouselistener, can clicked cells, not entire column.

you need jtable.getselectedcolumns(), returns selected column indexes, need access tablemodel (package javax.swing.table)

int[] columns = jtable.getselectedcolumns(); tablemodel model = jtable.getmodel(); int rowcount = model.getrowcount(); string[][] output = new string[columns.length][rowcount]; (int = 0; < columns.length; i++)     (int row = 0; row < rowcount; row++){         int column = jtable.convertcolumnindextomodel(columns[i]);         output[i][row] = model.getvalueat(row, column).tostring();     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -