Here you can find the source of writeRow(DefaultTableModel table, List
row
.
Parameter | Description |
---|---|
table | a parameter |
data | a list of data containing the train id, train locations and their timing. |
row | starting row. |
true
if we can schedule the train from the starting row, false
otherwise.
private static boolean writeRow(DefaultTableModel table, List<String[]> data, int row)
//package com.java2s; //License from project: LGPL import java.util.List; import javax.swing.table.DefaultTableModel; public class Main { /**/*w w w.j a v a 2 s . c o m*/ * Writes data to the table starting from <code>row</code>. * * @param table * @param data * a list of data containing the train id, train locations and * their timing. * @param row * starting row. * @return <code>true</code> if we can schedule the train from the starting * row, <code>false</code> otherwise. */ private static boolean writeRow(DefaultTableModel table, List<String[]> data, int row) { String trainId = data.get(0)[0].trim(); String[] locations = data.get(1); String[] time = data.get(2); int cols = table.getColumnCount(); int counter = 0; for (int i = 0; i < locations.length; i++) { if (i - 1 >= 0) { counter += Integer.parseInt(time[i - 1].trim()); } for (int j = 0; j < Integer.valueOf(time[i].trim()); j++) { int rows = table.getRowCount(); int column = table.findColumn(locations[i].trim()); if (counter + row + j >= rows) { String[] tmpData = new String[cols]; table.insertRow(rows, tmpData); } table.setValueAt(new String(trainId), counter + row + j, column); } } return true; } }