Here you can find the source of convertTableToList(DefaultTableModel table)
Parameter | Description |
---|---|
table | a parameter |
private static List<String> convertTableToList(DefaultTableModel table)
//package com.java2s; //License from project: LGPL import java.util.List; import java.util.Vector; import javax.swing.table.DefaultTableModel; public class Main { /**//from w w w . j a v a 2s.c o m * Returns a list as a table with the first line representing the name of * the columns. The other rows represent table data. * * @param table * @return a synchronized list with table data. */ private static List<String> convertTableToList(DefaultTableModel table) { List<String> schedule = new Vector<String>(); StringBuilder builder = new StringBuilder(); int numCol = table.getColumnCount(); int numRow = table.getRowCount(); // Add column names for (int i = 0; i < numCol; i++) { builder.append(table.getColumnName(i)).append(" "); } schedule.add(builder.toString()); // build data for (int i = 0; i < numRow; i++) { builder = new StringBuilder(); for (int j = 0; j < numCol; j++) { String s = (String) table.getValueAt(i, j); if (s == null) { s = "#"; } s = s.trim(); builder.append(s).append(" "); } schedule.add(builder.toString()); } return schedule; } }