当按钮添加时,
我正在尝试将数据从 a 获取JTextField
到 aJTable
ActionListener
:
public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if (src == AddBtn) {
System.out.println("HELLOO");
String nextRowId = Integer.toString(model.getRowCount());
model.addRow(new Object[] { nextRowId, LatText.getText(),
LongText.getText(), EvlText.getText() });
} else if (src == NextBtn) {
} else if (src == perviousBtn) {
}
}
表:
String columns[] = { "ID", "Name", "Age", "Gender" };
Object data[][] = { { "0", "Tom", new Integer(20), "Male" },
{ "1", "Tina", new Integer(18), "Female" },
{ "2", "Raj", new Integer(19), "Male" },
{ "3", "Tina", new Integer(18), "Female" },
{ "4", "Raj", new Integer(19), "Male" },
{ "5", "Tina", new Integer(18), "Female" }
};
DefaultTableModel model = new DefaultTableModel(data, columns);
完整代码: http: //pastebin.com/9R9QyXdw?
单击添加时没有任何反应。
编辑
我已将其更正为:
JTable dataTable = new JTable(model);
但仍然没有添加数据。谢谢你。