새 레코드를 추가하기 위해 JDialog가있는 테이블이 있습니다. Button을 추가 할 때 클릭하고 새 레코드를 추가하고 JDialog를 열고 JDialog 창을 닫은 다음 모든 열을 null
반환합니다. 내 테이블 행의.null을 반환합니다. JDialog를 닫을 때
이 내 JDialog를 생성자입니다 :
public class AddBookDialog extends JDialog implements ActionListener {
public AddBookDialog(JFrame owner) {
super(owner, "Add New Book", true);
initComponents();
saveBtn.addActionListener(this);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cancelBtn) dispose();
else if (e.getSource() == saveBtn) saveAction();
}
}
public void saveAction() {
if (nameTf.getText().trim().length() != 0) {
if (!haveDigit(nameTf.getText().trim())) setBookName(nameTf.getText().trim());
else {
JOptionPane.showMessageDialog(null, "Book Name have digit");
return;
}
} else {
JOptionPane.showMessageDialog(null, "Enter Book Name");
return;
}
if (isbnTf.getText().trim().length() != 0) {
if (haveSpace(isbnTf.getText().trim()) || haveLetter(isbnTf.getText().trim())) {
JOptionPane.showMessageDialog(null, "Enter Correct ISBN");
return;
}
setIsbn(isbnTf.getText().trim());
} else {
JOptionPane.showMessageDialog(null, "Enter Book ISBN");
return;
}
setBorrowStatus("No");
setDate(dateGenerate());
dispose();
}
내 테이블 GUI 클래스에서이 문제를 제어하려고 :
public class BookPage_Admin extends JFrame implements ActionListener {
...
public void addAction() {
AddBookDialog dialog = new AddBookDialog(this);
if (dialog.getBookName() != null && dialog.getIsbn() != null && dialog.getBorrowStatus() != null &&
dialog.getDate() != null) {
Object[] added = new Object[]{dialog.getBookID(), dialog.getBookName(), dialog.getIsbn(), dialog.getBorrowStatus(), dialog.getDate()};
model.addRow(added);
}
}
}
하지만 난 그것을 닫을 때 여전히 내 행 null
가 반환합니다.
null
닫는 방법을 막는 방법?
더 나은 도움을 더 빨리 [SSCCE] (http://sscce.org/), 짧고, 실행 가능한, 컴파일 가능한, 그냥 오전 문제에 대해 – mKorbel
'model'이 테이블의 모델을 섀도우하게 만들지 않는지 확인하십시오. – trashgod
@trashgod 더 설명해 주시겠습니까? – Sajad