Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Bhausaheb Mali
java
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


how set the header to the tablemodel


Advertisement
View Answers

June 25, 2011 at 11:03 AM


public class deletePanel extends JPanel { deletePanel () { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:testDSN"); Statement s = con.createStatement(); ResultSet r =s.executeQuery("SELECT * FROM testtable " );

            String data[][]={{}};
            String data1[]={"a","b","c"};


            DefaultTableModel model = new DefaultTableModel(data,data1);
            /*model.addColumn("Std No");
            model.addColumn("Std name");
            model.addColumn("class");*/
            //System.out.println(model.getColumnName(1));

              while(r.next())
            {
            String s1=String.valueOf(r.getInt("stdno"));
            String[] rw={ s1, r.getString("stdname"), r.getString("class")};
            model.addRow(rw);
            }


            JTable table=new JTable();


            /*TableColumn c = new TableColumn(0);
            c.setHeaderValue(model.getColumnName(0));*/

            table.setModel(model);

// table.getColumnModel().getColumn(0).setHeaderValue(" std No"); // table.getColumnModel().getColumn(1).setHeaderValue(" Name"); // table.getColumnModel().getColumn(2).setHeaderValue(" Class");

            add(table);
            }catch(Exception e1){}

}

/*public void ChangeName(JTable table, int col_index, String col_name){
    table.getColumnModel().getColumn(col_index).setHeaderValue(col_name);*/

/*

    ChangeName(table,0,"Stu_name");
    ChangeName(table,2,"Paper");
    JTableHeader header = table.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane pane = new JScrollPane(table);
    panel.add(pane);
    frame.add(panel);
    frame.setUndecorated(true);
    frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    frame.setSize(500,150);
    frame.setVisible(true);
}

    public void ChangeName(JTable table, int col_index, String col_name){
    table.getColumnModel().getColumn(col_index).setHeaderValue(col_name);
}*/

}



June 25, 2011 at 11:08 AM




Related Tutorials/Questions & Answers:
 

 

 

DMCA.com