是否可以一次更新JTable整行,而不是列? 這是我下面 程序目前我能修改只 使用是否可以立即更新JTable整行?
model.setValueAt("1111", 0, 0)
我能使用
model.setValueAt(new Object[]{"1111","Pavan","Developer"}, 0, 0);
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
public class Preethi {
protected void initUI() {
final DefaultTableModel model = new DefaultTableModel(new String[] {
"Id", "Name", "Desg" }, 0);
final JTable table = new JTable(model);
// table.setFillsViewportHeight(true);
JFrame frame = new JFrame(Preethi.class.getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollpane = new JScrollPane(table);
frame.add(scrollpane, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
Vector vec = new Vector();
vec.add("1122");
vec.add("Iraneee");
vec.add("Dev");
model.insertRow(0, vec);
model.setValueAt("1111", 0, 0);
//model.setValueAt(new Object[]{"1111","Pavan","Developer"}, 0, 0);
}
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Preethi().initUI();
}
});
}
}
_Update entire row_。所以我認爲刪除該行並添加新行。 – Amarnath