我不能让我的JTable显示任何东西 [英] I can't get my JTable to show anything

查看:119
本文介绍了我不能让我的JTable显示任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让我的gui显示Jtable,为什么我不知道,我没有得到任何错误,当我打印一些东西到屏幕上我得到9列。所以我得到了数据。但是我做错了我不知道。

I cant get my gui to show the Jtable, why i dont know and i dont get any error and when i print something to the screen i get 9 colum. so i get data. but what i'm doing wrong i have no idea about that.

我的GUIOdreHandler看起来像这样

My GUIOdreHandler looks like this

public GUIOrdreHandler(){

            KaldSQL ks = new KaldSQL();
            ResultSet rs;

        }

        public static DefaultTableModel buildTableModel(ResultSet rs)
                throws SQLException {

            java.sql.ResultSetMetaData metaData = rs.getMetaData();

            // names of columns
            Vector<String> columnNames = new Vector<String>();
            int columnCount = metaData.getColumnCount();
            for (int column = 1; column <= columnCount; column++) {
                columnNames.add(metaData.getColumnName(column));
                System.out.println(columnCount);
            }

            // data of the table
            Vector<Vector<Object>> data = new Vector<Vector<Object>>();
            while (rs.next()) {
                Vector<Object> vector = new Vector<Object>();
                for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
                    vector.add(rs.getObject(columnIndex));
                }
                data.add(vector);
            }

            return new DefaultTableModel(data, columnNames);

            }

我的GUIHentOrdre看起来像这样

And my GUIHentOrdre looks like this

public GUIHentOrdre(){

        try {
            con = ks.connectNow();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        JPanel info = new JPanel();
        info.setLayout(new BorderLayout());
        button = new JButton("button");
        info.add(button, BorderLayout.CENTER);
        add(button);
        ResultSet rs = ks.Hentalleordreliste(con);
        GUIOrdreHandler gh = new GUIOrdreHandler();

        try {
            table = new JTable(gh.buildTableModel(rs));

            System.out.println(table);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        info.add(table, BorderLayout.CENTER);
        add(table);
    }
}




我试过了什么谷歌,预订北方工作,所以请帮助我
:D

I have tried anything google, book northing works, so please help me :D


推荐答案

关于代码中的错误

JPanel info = new JPanel();
info.setLayout(new BorderLayout());
button = new JButton("button");
info.add(button, BorderLayout.CENTER);
add(button);




  • 删除关于的代码行添加(按钮); 到(代码不完全在谈论)

    • remove code line about add(button); to the (code not exactly talking about)

      更改 info.add(按钮) ,BorderLayout.CENTER); NORTH SOUTH

      您没有将 JTable (在 JScrollPane 中)添加到 JPanel 正确

      you not added JTable (in JScrollPane) to the JPanel correctly

      伪代码

      JPanel info = new JPanel();
      info.setLayout(new BorderLayout());
      button = new JButton("button");
      info.add(button, BorderLayout.SOUTH);
      JTable table = new JTable (ClassOrVoidOrModelNameReturnsTableModel)
      JScrollPane scroll = new JScrollPane(table)
      info.add(scroll, BorderLayout.CENTER);
      



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆