Java JTable设置了JButton和JTextField,但输出没有显示任何内容

时间:2017-07-17 10:01:25

标签: java jtable jbutton jtextfield

我编写了以下代码来制作JTable。我正在练习通过设置JButtonJTextField来修改行的值,但JButtonJTextField的输出是看不见的。

public class quotingtable extends javax.swing.JFrame {
    DefaultTableModel model;
    JTable table;
    String col[] = { "Symbol", "Name", "LastPrice" };
    JButton button = new JButton("Set Value at 1, 1");
    JTextField text = new JTextField(20);
    JPanel panel = new JPanel();

    public void start() {
        model = new DefaultTableModel(col,50);
        table = new JTable(model) {
            @Override
            public boolean isCellEditable(int arg0 ,int arg1) {
                return false;
            }
        };

        panel.add(table);
        panel.add(text);
        panel.add(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String value = text.getText();
                model.setValueAt(value, 1, 0);
            }
        });

        JScrollPane pane = new JScrollPane(table);
        table.setValueAt("VNM", 0, 0);
        add(pane);
        setSize(500, 400);
        setLayout(new FlowLayout());
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String args[]) {
        new quotingtable().start();
    }
}

0 个答案:

没有答案