Results 1 to 3 of 3
  1. #1
    indra00 is offline Member
    Join Date
    Jun 2010
    Location
    India
    Posts
    8
    Rep Power
    0

    Exclamation Adding Checkbox to Jtable through vectors

    Hello, what I am trying to do is to add JCheckbox to a vector used as row and then pass that vector vector to jtable to show up.But its not showing though no error. Please correct my code or show me what to do...its urgent as I am to finish this project within next two days!!!

    here is the code---
    First this under the an actionperformed method--
    Java Code:
    ResultSet rs= JDBC_Con.fac_stud_list(year,dept);
                        ResultSetMetaData rsmd=rs.getMetaData();
                        Vector colnames=new Vector();
                        Vector rows=new Vector();
                        for(int i=1;i<=rsmd.getColumnCount();i++)
                         {
                             colnames.addElement(rsmd.getColumnName(i));
    
                         }
                        colnames.addElement(new String("Attendance"));
    
                             while(rs.next()){
                             rows.addElement(getrows1(rs,rsmd));
    
                          };
    
                            showtable1(colnames,rows);
                        }

    and then this is the part ,by the way check[count] came from here
    Java Code:
    final JCheckBox check[]=new JCheckBox[70];
    ---------


    Java Code:
    Vector getrows1(ResultSet rs,ResultSetMetaData rsmd)
        {
    
            Vector row1=new Vector();
            
            try{
    
    
          for(int i=1;i<=rsmd.getColumnCount()+1;i++)
          {
            if(i==4)
            {
                  row1.addElement(check[count]);
                  count++;
                  return row1;
            }
    
              switch(rsmd.getColumnType(i))
              {
    
                  case 12:
    			row1.addElement(rs.getString(i));
                            break;
                  case 8:
                      row1.addElement(rs.getLong(i));
                      break;
                  default:
                     JOptionPane.showMessageDialog(null,"Failed to retrieve datatype");
    
              }
              
            
              
          }
    
          
            }
            catch(Exception ae)
            {
                JOptionPane.showMessageDialog(null,"Failed to retrieve data"+ae);
            }
            return row1;
        }
    void showtable1(Vector colname,Vector rows)
        {
           
            JTable table=new JTable(rows,colname);        
            JScrollPane pane=new JScrollPane(table);
            JFrame frame=new JFrame("Student Attendance Input");
            frame.getContentPane().add(pane);
            frame.setVisible(true);     
            frame.setSize(new Dimension(400,600));
            frame.setResizable(false);
            
            
    
        }
    Please help!!!
    Last edited by indra00; 12-07-2010 at 07:17 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    If you want to show a check box in a JTable, you don't do it by adding a JCheckBox object to the table's data. Instead you do it by adding Boolean objects to the JTable's model, and override the model's getColumnClass(int columnIndex) method to return Boolean.Class. Either that or have it return the results of getClass on the objects held in the table's 0th row. The Swing tutorial will help you with this: How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  3. #3
    indra00 is offline Member
    Join Date
    Jun 2010
    Location
    India
    Posts
    8
    Rep Power
    0

    Default

    ok thanx after a lot of try i understood what to be done . thanx!

Similar Threads

  1. Adding elements in array list and vectors using threads
    By hina.yousuf@seecs.edu.pk in forum Advanced Java
    Replies: 2
    Last Post: 10-10-2010, 03:07 AM
  2. Replies: 3
    Last Post: 07-27-2010, 09:52 AM
  3. CheckBox in JTable
    By nikosa in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2009, 05:01 AM
  4. Sorting JTable (Vectors) Problem
    By ramapple in forum AWT / Swing
    Replies: 6
    Last Post: 07-06-2009, 11:15 PM
  5. checkBox in Jtable renderining problem
    By pothraj in forum AWT / Swing
    Replies: 1
    Last Post: 12-18-2008, 11:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •