Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不打印JTable列名_Java_Mysql_Swing - Fatal编程技术网

Java 不打印JTable列名

Java 不打印JTable列名,java,mysql,swing,Java,Mysql,Swing,当我创建两个向量(数据、列名)并在JTable中使用它们来显示带有列标题的行时,它只显示行,而不显示列标题 在JOptionPane中,列标题显示良好。我认为粗体是错误的地方,因为它没有正确地获取列名 public void displayLettingProperties()引发SQLException{ Connection conn = null; try { conn = DriverManager.getConnection(CONN_ST

当我创建两个向量(数据、列名)并在JTable中使用它们来显示带有列标题的行时,它只显示行,而不显示列标题

在JOptionPane中,列标题显示良好。我认为粗体是错误的地方,因为它没有正确地获取列名

public void displayLettingProperties()引发SQLException{

    Connection conn = null;
    try {       
        conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
        System.out.println("Connected to database.");       

         // The Connection is obtained

        Statement Stmt = (Statement) conn.createStatement();
    //  Stmt.execute(createPropertyTable);

        ResultSet rs = Stmt.executeQuery("select * from PropertyLettings ORDER BY propertyBedrooms ASC");

        // It creates and displays the table
        **JTable table = new JTable(buildTableModel(rs));**


     // Set Column Widths

        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        table.getColumnModel().getColumn(1).setPreferredWidth(50);
        table.getColumnModel().getColumn(2).setPreferredWidth(350);
        table.getColumnModel().getColumn(3).setPreferredWidth(100);
        table.getColumnModel().getColumn(4).setPreferredWidth(100);
        table.getColumnModel().getColumn(5).setPreferredWidth(350);
        table.getColumnModel().getColumn(6).setPreferredWidth(100);
        table.getColumnModel().getColumn(7).setPreferredWidth(130);



     //   JOptionPane.showMessageDialog(null, new JScrollPane(table));

        final JPanel panelOne = new JPanel();
        panelOne.setVisible(true);
        panelOne.setBackground(Color.LIGHT_GRAY);
        // JFRAME
        final JFrame topFrame = new JFrame();
        topFrame.setSize(1550, 300);
        topFrame.setLocationRelativeTo ( null );
        topFrame.setVisible(true);
        topFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        // PUT TOGETHER
        topFrame.add(panelOne);

        panelOne.add(table);


        panelOne.revalidate();
        panelOne.repaint();


    } catch (SQLException e) {
        System.err.println("Cannot connect to database." + e);


    } finally {

    if(conn != null){
        conn.close();

      }

    } 

正如建议您在使用此代码时所做的那样,在添加到UI之前,您需要将表添加到
JScrollPane

panelOne.add(new JScrollPane(table));

查看并了解更多详细信息…

您的问题是什么?