[英]Jtable no repaint
在这里,我有一个初始化Jtable的程序,以便以后如果用户想要更新TABLE的数据,可以通过导入它来使它成为它。
Vector<String> rowOne = new Vector<>(); //Uses this Dta instead of Desearilze.
rowOne.addElement("Harry");
rowOne.addElement("100414");
rowOne.addElement("21");
rowOne.addElement("239438");
rowOne.addElement("24/24/23");
rowOne.addElement("30000");
Vector<Vector> rowData = new Vector<>();
rowData.addElement(rowOne);
columnNames = new Vector<>();
columnNames.addElement("Name");
columnNames.addElement("Cc");
columnNames.addElement("Age");
columnNames.addElement("Phone");
columnNames.addElement("Date");
columnNames.addElement("Amount");
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
table = new JTable(model);
scrollTable = new JScrollPane(table);
scrollTable.setBounds(23, 77, 769, 242);
scrollTable.setViewportView(table);
contentPane.add(scrollTable);
button.addActionListener(this);
public void actionPerformed(ActionEvent e)
{
else if (e.getActionCommand().equals("import"))
{
JFileChooser file = new JFileChooser();
int i = file.showOpenDialog(this);
if(i == JFileChooser.APPROVE_OPTION)
{
File f = file.getSelectedFile();
String filePath = f.getPath();
try
{
ObjectInputStream input = new ObjectInputStream(new FileInputStream(filePath));
Vector vectorData = (Vector)input.readObject();
data = new DefaultTableModel(vectorData, columnNames);
table.setModel(data);
}
}
}
}
问题是,当我为GUI中的Jtable导入表的数据时,该如何显示?
要将数据更改通知JTable,请使用tableModel.fireTableDataChanged() :
table.setModel(data);
//add
data.fireTableDataChanged();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.