public void readCar() {
String choice = String.valueOf(car_combo1.getSelectedItem());
int ctr = 0;
String filename = null;
if (choice.equals("STATE-Description")) {
filename = TEXT_CAR1.getText();
ctr = 12;
} else if (choice.equals("DISCAS-Camera")) {
filename = TEXT_CAR2.getText();
ctr = 3;
} else if (choice.equals("DISCAS-CAR(for removal)")) {
filename = TEXT_CAR3.getText();
ctr = 11;
} else if (choice.equals("DISCAS-PAR(for removal)")) {
filename = TEXT_CAR4.getText();
ctr = 9;
} else if (choice.equals("Closing CAS for chg w/ customer initiated")) {
filename = TEXT_CAR5.getText();
ctr = 11;
}
try {
File file = new File(filename);
FileReader fr = new FileReader(file.getAbsoluteFile());
BufferedReader br = new BufferedReader(fr);
for (int i = 0; i < ctr; i++) {
dataCar[i] = br.readLine();
String[] temp;
temp = dataCar[i].split("\\*");
car_table.setValueAt(temp[0], i, 0);
car_table.setValueAt(temp[1], i, 1);
}
} catch (IOException e) {
e.printStackTrace();
}
}
This is the read function
private void car_combo1ActionPerformed(java.awt.event.ActionEvent evt) {
String choice = String.valueOf(car_combo1.getSelectedItem());
JTableHeader th = car_table.getTableHeader();
if (choice.equals("STATE-Description")) {
car_table.getColumnModel().getColumn(0).setHeaderValue("STATE");
car_table.getColumnModel().getColumn(1).setHeaderValue("Description");
String[] change_choice_to = {"-", "1006", "1009", "1011", "1013", "1015", "1017", "1018", "1019", "1020", "1021", "1022", "1023"};
DefaultComboBoxModel model = new DefaultComboBoxModel(change_choice_to);
car_combo2.setModel(model);
DefaultTableModel model2 = (DefaultTableModel) car_table.getModel();
model1.fireTableDataChanged();
readCar();
}
}
table.repaint(); and tableModel.fireTableDataChanged(); doesn't work. I tried both of those function but the jtable wouldn't refresh. The notepad with more lines in it stays in the jTable when a lesser lined notepad is called.
I'm using BufferedReader and FileReader to read it from the notepad.
Is there anyway to refresh the table into its default then show the data from the notepad again? Thank you.