[英]IDEA Java swing GUI form Jtable. table model is overwritten by auto generated code
Some tutorials say I can use Jtable like this: 一些教程说我可以像这样使用Jtable:
JTable table = new JTable(myModel); // where myModel is a table model
But how can I do that if the IDEA GUI Form automatically generates the code? 但是,如果IDEA GUI表单自动生成代码,该怎么办? I can't use the constructor function to pass the model. 我不能使用构造函数来传递模型。
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by mark on 17-11-8.
*/
public class StudentManager {
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JTextField textField4;
private JTextField textField5;
private JPanel myPanel;
private JButton saveButton;
private JButton sumButton;
private JButton averageButton;
private JButton sortButton;
private JButton button5;
private JTable table1;
public StudentManager() {
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
}
public static void main(String[] args) {
JFrame frame = new JFrame("StudentManager");
frame.setContentPane(new StudentManager().myPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Your generated code : 您生成的代码:
JTable table = new JTable();
Later, your code to set the model : 稍后,您的代码来设置模型:
DefaultTableModel model = new DefaultTableModel();
model.addRow(...*your data*...);
table.setModel(model);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.