한 테이블에서 다른 테이블로 행을 추가하려고하는데 datepicker도 있고 날짜가 일치하는지 확인하고 싶습니다.테이블 행 비교, 중복 방지
int i=jTable1.getSelectedRow();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
jXDatePicker1.setFormats(dateFormat);
String date = dateFormat.format(jXDatePicker1.getDate()).toString();
String c1=jTable1.getValueAt(i, 0).toString();
String c2=jTable1.getValueAt(i, 1).toString();
String c3=jTable1.getValueAt(i, 2).toString();
String c4=jTable1.getValueAt(i, 3).toString();
String c5=price.getText().toString();
String c6=jTextField1.getText().toString();
String c7=date;
model.addRow(new Object[]{c1, c2, c3, c4, c5, c6, c7});
jTable2.setModel(model);
while(jTable2.getRowCount()>1) {
for (int k = 0; k < jTable2.getRowCount(); k++) {
if (c7.equals(jTable2.getValueAt(k, 6).toString())) {
}
JOptionPane.showMessageDialog(null, "Record exist");
model.removeRow(jTable2.getRowCount()-1);
return;
}
}
그것은 날짜가 다른 경우에도 오류가 발생합니다 :
아무것도 내가
while(jTable2.getRowCount()>1) {
for (int k = 0; k < jTable2.getRowCount(); k++) {
int t1=Integer.parseInt(jTable2.getValueAt(k, 0).toString());
if (c1==t1) {
JOptionPane.showMessageDialog(null, "Record exist");
model.removeRow(jTable2.getRowCount()-1);
return;
}
}
}
가 int로서 두 값을 구문 분석하는 대신 날짜의 ID를 비교하는 시도 일 것 같다 아직 아무것도. 루프가 작동하지 않습니다.
나는 당신의 들여 쓰기를 고정. if 문이 아무 것도 수행하지 않는다는 것이 분명해졌습니다. – mavroprovato
변경된 스틸 그다지 일 동안 (jTable2.getRowCount()> 1) {(INT에서 K = 0; K
user3316744