I have a table that represented a lot data. This is the code to created that table
DefaultTableModel model = (DefaultTableModel) Main_Menu.jTable3.getModel(); //Main menu is my form
List<ReportCalculateSimiliarity> theListRCS = new ArrayList<ReportCalculateSimiliarity>();
ReportCalculateSimiliarity rcs = new ReportCalculateSimiliarity();
rcs.setNameOfMainFile(name);
rcs.setNameOfComparingFile(enemy);
rcs.setLevenstheins(resultOfLevenstheins);
rcs.setSmithWaterman(resultOfSmithWaterman);
theListRCS.add(rcs);
for (ReportCalculateSimiliarity reportCalculateSimiliarity : theListRCS) {
model.addRow(new Object[]{
reportCalculateSimiliarity.getMainFile(),
reportCalculateSimiliarity.getComparingFile(),
reportCalculateSimiliarity.getLevenstheins(),
reportCalculateSimiliarity.getSmithWaterman(),
});
}
and then, I have a jbutton to reset that data. The code is like this :
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
int confirm = JOptionPane.showConfirmDialog(null, "clear ?", "end session", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (confirm == JOptionPane.YES_OPTION) {
//this is to clear that jtable
}
}
I have to do this, because my jTable is connected to a jfreechart. If the data in jtable is not clear, the jfreechart is going to be wrong because previous data still there and make a bar in my bar chart. the bar chart code like this :
public final CategoryDataset createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.clear();
String algoritma1 = "Levensthein";
String algoritma2 = "SmithWaterman";
for (int i = 0; i < Main_Menu.jTable3.getRowCount(); i++) {
Object fileName = Main_Menu.jTable3.getValueAt(i, 1);
String fileNameToString = fileName.toString();
Object nilaiLevensthein = Main_Menu.jTable3.getValueAt(i, 2); // Ambil Nilai Persentase Levensthein
double count1 = Double.parseDouble(nilaiLevensthein.toString());
Object nilaiSmithWaterman = Main_Menu.jTable3.getValueAt(i, 3);
double count2 = Double.parseDouble(nilaiSmithWaterman.toString());
dataset.addValue(count1, algorithm1, fileNameToString);
dataset.addValue(count2, algorithm2, fileNameToString);
}
For the help, thank you so much...