I know this has been asked, but I can't seem to get this to work. I have a jTable with four columns inside of a JscrollPane. I can only see 3 columns though when I scroll? Can anyone else see what may be going wrong?
I checked these threads, but they didn't help: JTable Missing Column Headers Issues with JTable, I can add to the table but can't see all rows
Thanks
Code:
/*
 * FullDatabaseTable.java
 *
 * Created on ...
 */
package brainstormer95;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import brainstormer95.TableCellLongTextRenderer;
/**
 *
 * @author ...
 */
public class FullDatabaseTable extends JPanel {
    private Vector stringInfo;
    Font font2 = new Font("Calibri", Font.BOLD, 16);
    Font font3 = new Font("Calibri", Font.BOLD, 30);
    private JTable table;
    private JScrollPane scrollPane = new JScrollPane(table);
    /** Creates new form FullDatabaseTable */
    public FullDatabaseTable() throws SQLException {
        //initComponents();
    }
    public void createTable() throws SQLException {
        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/brainstormer", "me", "me");
        PreparedStatement order = con.prepareStatement(" SELECT ITEM_NAME,SPECIFIC_PURPOSE,EXAMPLE_1,EXAMPLE_2 FROM APP.INVENTORY ORDER BY ITEM_NAME");
        ResultSet rs = order.executeQuery();
        //Column Names
        int columnCount = rs.getMetaData().getColumnCount();
        Vector columns = new Vector(columnCount);
        for (int i = 1; i <= columnCount; i++) {
            columns.add(rs.getMetaData().getColumnName(i));
        }
        //Cell data
        Vector stringVector = new Vector();
        while (rs.next()) {
            stringInfo = new Vector(columnCount);
            for (int i = 1; i <= columnCount; i++) {
                stringInfo.add(rs.getString(i));
            }
            stringVector.add(stringInfo);
        }
        //Jtable Properties
        Dimension tableSize = new Dimension();
        tableSize.setSize(1400, 800);
        Dimension scrollSize = new Dimension();
        scrollSize.setSize(1000, 600);
        //JTable Creation
        table = new JTable(stringVector, columns);
        table.setPreferredSize(tableSize);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setFont(font2);
        //needs to be set on the appropriate column indicy
        table.getColumnModel().getColumn(1).setCellRenderer(new TableCellLongTextRenderer());
        //AutoScrolls
        scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setPreferredSize(scrollSize);
        //Grid Properties
        table.setShowGrid(true);
        table.setGridColor(Color.LIGHT_GRAY);
        //Header Properties
        JTableHeader header = table.getTableHeader();
        header.setBackground(Color.pink);
        header.setFont(font3);
        header.setAutoscrolls(true);
        //Final
        add(scrollPane);
        setVisible(true);
        setBackground(Color.LIGHT_GRAY);
    }
    public JComponent returnGUI() {
        return this;
    }
}
 
    