操作 jTable Java 中的字段
我已使用以下代码填充我的 jTable。 它有两列,第一列有变量名称,第二列是其依赖项列表。 用户可以通过从 jTable 的列表中选择来更改依赖关系。
当用户更改值时,我想将行添加到另一个 jTable (这将是用户不可编辑的。我该怎么做?
填充表的代码是
Vector<Vector> data = new Vector<Vector>();
for (String v : acn.getVariableNames()) {
Vector tmp = new Vector();
tmp.add(v);
ArrayList<String> temp = new ArrayList<String>();
for (String u : acn.getVariableDomain(v)) {
temp.add(u);
}
tmp.add(temp);
data.add(tmp);
}
Vector names = new Vector();
names.add("Variable");
names.add("Domain Value");
DefaultTableModel dt = new DefaultTableModel();
dt.setDataVector(data, names);
jTable2.setModel(dt);
jTable2.getColumnModel().getColumn(1).setCellEditor(new ChangeImpactEditor());
jTable2.getColumnModel().getColumn(1).setCellRenderer(new TableListRenderer());
I have populated my jTable with the following Code. It has two columns, the first has variable name and the second is a list of its dependencies. The user can change the dependencies by selecting them from the list in the jTable.
When the user changes a value, I want to row to be added to another jTable (which would be no user editable. How would I do that?
The code to populate the table is
Vector<Vector> data = new Vector<Vector>();
for (String v : acn.getVariableNames()) {
Vector tmp = new Vector();
tmp.add(v);
ArrayList<String> temp = new ArrayList<String>();
for (String u : acn.getVariableDomain(v)) {
temp.add(u);
}
tmp.add(temp);
data.add(tmp);
}
Vector names = new Vector();
names.add("Variable");
names.add("Domain Value");
DefaultTableModel dt = new DefaultTableModel();
dt.setDataVector(data, names);
jTable2.setModel(dt);
jTable2.getColumnModel().getColumn(1).setCellEditor(new ChangeImpactEditor());
jTable2.getColumnModel().getColumn(1).setCellRenderer(new TableListRenderer());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖
我这样做的方法是从您的 TableModel 。
用户编辑值后,JTable 会调用 setValue 方法
在您的重写方法中,您可以在其他表模型中设置该值
The way i would do it is to override
from your TableModel.
The setValue method get called by the JTable after the user has editted a value
In your overriden method you then can set the value in the other tablemodel