I apologize for my lack of background in Swing, but I am coming here with a JTable question. My table is structured as:
12 columns across and the amount of rows depend on the incoming data.
I was wondering if there's a way to take the first column's data (Col1) and to check to see if the value exists in the table already, and if so, update the remaining 11 columns for that row, if necessary, and if not add it to the table.
Here's a snippet of my GUI Class
public class ShowGUI extends JFrame {
String [] colNames = new String[] {"Col1", "Col2" "Col3","Col4","Col5","Col6", "Col7", "Col8", "Col9", "Col10", "Col11", "Col12"};
public showGUI() {
PublicTransportation example = new Public Transportation();
example.getRouteTaken();
List<Object> routeList = example.getList();
final Object[][] rowData = new Object[routeList.size() / colNames.length][colNames.length];
for (int i = 0; i < rowData.length; i++) {
for (int j = 0; j < rowData[i].length; j++) {
rowData[i][j] = routeList.get( i * colNames.length + j);
}
}
DefaulTableModel myModel = new DefaultTableModel(rowData, colNames);
final JTable table = new JTable(myModel);
table.setAutoCreateColumnsFromModel(true);
// JFrame, JPanel
}
}
As it stands, my table displays all of the rows, of course, does not factor in duplicates. I have looked into Hashing the column, but I am having trouble implementing it. Does anyone have any recommendations?
EDIT: As I receive data from the getRouteTaken method from the Public Transportation class, I want to display the data on the table. I need to call this method to populate the table. A new row will be inserted if the first value of the first column does not exist already in the table. If the value does already exist, then I want to check if any of the values for the rest of the columns for that particular row have changed for a previous state. If so, I want to update them.
Example:
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col11 Col12
data1 data2 data3 data4 data5 data6 data7 data8 data9 data10 data11 data12
If data1's value exists in the table already, then check to see if data values 2-12 have changed. If so, update them. If data1's value does not exist, then add an entirely new row.
Thank you in advance.