0

私は次のクラスを持っています:

public class customer_master extends javax.swing.JInternalFrame {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    JFrame parent;
    public customer_master(JFrame parent) {

        this.parent=parent;
        initComponents();

        try {
            String qry="select customer_code, customer_name, customer_address, customer_created_time from customer";
            database.JavaConnect jc= new JavaConnect(); 
            con = jc.ConnectDB();
            ps = con.prepareStatement(qry);
            rs = ps.executeQuery();
            jTable1.setModel(DbUtils.resultSetToTableModel(rs));
            con.close();
        }
        catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }    
}

列の名前も変更しますが、列名を変更せずにrsを追加したいのですが、助けていただければ幸いです。前もって感謝します。

4

2 に答える 2

1

あなたの質問は、新しいResultSetを使用して既存のJTableを再メッシュしていることを意味します。したがって、初めてJTableを作成し、各列に名前を割り当てるときは、次を追加する必要があります。

JTable table = new JTable(...);
table.setAutoCreateColumnsFromModel( false );

これにより、TableColumnModelを再作成しないようにテーブルに指示されるため、すべての列とカスタムレンダラーおよびエディターが残ります。

于 2013-02-16T16:11:57.810 に答える