【问题标题】:Insert data to JPanel inside JTable -- JAVA向JTable里面的JPanel插入数据——JAVA
【发布时间】:2013-11-23 14:59:00
【问题描述】:

我找不到将数据插入 JTable 中的 JPanel 的方法。 任何人都可以帮我弄清楚吗?我做错了什么?

这是我的代码:

JTabbedPane tabProcessamentoSalarial = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.addTab("Remunera\u00E7\u00F5es", null, tabProcessamentoSalarial, null);

JPanel pnlAcumulados = new JPanel();
tabProcessamentoSalarial.addTab("Acumulados", null, pnlAcumulados, null);
        pnlAcumulados.setLayout(null);

        table_1 = new JTable();
        table_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
        table_1.setBounds(46, 36, 508, 160);
        pnlAcumulados.add(table_1);


        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(46, 36, 508, 160);
        pnlAcumulados.add(scrollPane);

        tblAcumulados = new JTable();
        tblAcumulados.setBounds(46, 36, 508, 160);
        tblAcumulados.setModel(new DefaultTableModel() {
            String[] columnNamesRui = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};

            Object[][] dataRui = {
                {"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)},
                {"John", "Doe", "Rowing", new Integer(3), new Boolean(true)},
                {"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)},
                {"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)},
                {"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)}
            };
        }
        );

【问题讨论】:

    标签: java swing jtable jpanel


    【解决方案1】:

    我做错了什么?

    您为什么更改 Swing 教程中的代码?教程代码可以正常工作,那么如果您不了解自己在做什么,为什么要对其进行更改?

    1. 您不应该使用空布局。
    2. 为什么不使用表格作为构造函数来创建滚动窗格?

    使用 How to Use Tables 上的 Swing 教程中的示例重新开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 2022-07-11
      • 1970-01-01
      相关资源
      最近更新 更多