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



Home Answers Viewqa Swing-AWT Not able to display jtable at runtime
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


i m
Not able to display jtable at runtime
2 Answer(s)      3 years and 8 months ago
Posted in : Swing AWT


Hello,

can anyone please help me. I am trying to create a dynamic table with checkboxes. Data are accessed from database. But it is not creating the table at runtime. It retrieves data from database properly. But I am not getting why it is not creating the table in a specified Panel (panTable). Below is the code:

int tasktotr=0;
Object[][] taskcells;
JTable ttable;

public void BuildTable() {
   Statement st;
   ResultSet rs;

   panTable.updateUI();
   String query="";
   try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       conn=DriverManager.getConnection("jdbc:odbc:dsndbPMA","","");
       st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
       query="select * from Task";
       rs=st.executeQuery(query);
       rs.last();
       tasktotr=rs.getRow();
       System.out.println("tasktotr="+tasktotr);
       taskcells=new Object[tasktotr][6];
       if(tasktotr>0){
           int cnt=0;
           rs.beforeFirst();
           for(int c=0;c<6;c++){
               if(c==cnt){
                   int r=0;
                   while(rs.next()){
                       if(c==0)
                           taskcells[r][c]=Boolean.FALSE;
                       else if(c==1)
                           taskcells[r][c]=rs.getString("Priority");
                       else if(c==2)
                           taskcells[r][c]=rs.getString("Subject");
                       else if(c==3)
                           taskcells[r][c]=rs.getString("Status");
                       else if(c==4)
                           taskcells[r][c]=rs.getString("DueDate");
                       else if(c==5)
                           taskcells[r][c]=rs.getString("%Complete");
                       else if(c==6)
                           taskcells[r][c]=rs.getString("Category");
                       r++;
                   }
               }
                rs.beforeFirst();
                cnt++;
           }
           rs.close();
           st.close();
           for(int i=0;i<tasktotr;i++){
               for(int j=0;j<6;j++){
                   System.out.println(taskcells[i][j]);
               }
           }
           TableModel tasktable=new TaskTableModel(tasktotr,7);
           ttable=new JTable(tasktable);

           TableColumnModel columnModel=ttable.getColumnModel();
           TableColumn column;
           for(int i=0;i<ttable.getColumnCount();i++) {
               column = columnModel.getColumn(i);
               if(i==0)
                   column.setPreferredWidth(40);
               if(i==1)
                   column.setPreferredWidth(40);
               if(i==2)
                   column.setPreferredWidth(150);
           }
           ttable.setRowHeight(18);
           ttable.setAutoResizeMode(ttable.AUTO_RESIZE_OFF);
           ttable.getTableHeader().setReorderingAllowed(false);

           JScrollPane scroll=new JScrollPane(ttable);
           scroll.setAutoscrolls(true);
           panTable.add(scroll);
           panTable.updateUI();
           panTable.revalidate();
       }
   }catch(Exception e){
       e.printStackTrace();
       JOptionPane.showMessageDialog(null,e.getMessage(),"Error!!",1);
   }
}


class TaskTableModel extends AbstractTableModel{
    int totrow,totcol;
    public TaskTableModel(int r,int c){
        totrow=r;
        totcol=c;
    }
    @Override
    public int getRowCount() {
        return totrow;
    }
    @Override
    public int getColumnCount() {
        return totcol;
    }

    public Object getValueAt(int r,int c) {
        return taskcells[r][c];
    }

    public String getColumnName(int c){
        if(c==0)
            return "Icon";
        else if(c==1)
            return "Priority";
        else if(c==2)
            return "Subject";
        else if(c==3)
            return "Status";
        else if(c==4)
            return "Due Date";
        else if(c==5)
            return "% Completed";
        else if(c==6)
            return "Category";
        else
            return "";
    }

    public void setValueAt(Object obj,int r,int c){

        taskcells[r][c]=obj;
        fireTableCellUpdated(r, c);
    }

    //Edit only first column.
    public boolean isCellEditable(int r,int c){
        return c==0;
    }

    //used to display checkbox else it will show true/false text instead of checkbox. n
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

}

Advertisement
View Answers

March 8, 2011 at 3:27 PM


Oh..I forgot to set panel's layout.Now its working..



March 26, 2011 at 1:07 PM


hi i get into a problem of scrolling table in jscrollpane..my vertical scroll is not working..i hope to get an answer



Related Tutorials/Questions & Answers:
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help... from database. But it is not creating the table at runtime. It retrieves data from...[][] taskcells; JTable ttable; public void BuildTable() { Statement st; ResultSet rs
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new... of implementing row filter to the 4th column of jtable with a textfield but its
Advertisements
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new... of implementing row filter to the 4th column of jtable with a textfield but its
Display both image and data into Swing JTable
Display both image and data into Swing JTable  How To Display both image and data into Swing JTable which is retrieved from MySQL database
display dinamic data in JTable - Swing AWT
display dinamic data in JTable  Hi, I need some help to development... and to read data in each files of this directory and to display it in one JTable... in this directory now i want to display the data of each files
how to sort the text file and display it in jtable
how to sort the text file and display it in jtable   my text file... ctgaggactcctcg i want to display the lines started with ">" symbol to be displayed in jtable and sequence like "CGGGAATTAA..." in jtextarea in netbeans . pls suggest
I am not able to display the selected value of my combobox
I am not able to display the selected value of my combobox   <?php echo "<select name=\"hello\">\n"; echo "<option value=\"NULL\">Select Value</option>\n"; $strQuery = "select unitcode,unitname from
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
Display Label and radio buttons runtime with respect to DB values
Display Label and radio buttons runtime with respect to DB values  Requirement: I am getting alertCondition,Y,W values from DB the the cooresponding... can we get selected values of radiobuttons at runtime and updated back to DB
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display Records From MS Access Database To JTable. Plz Help Me  Hi Friend...){ System.out.println(e); } JTable table = new JTable(data, columnNames); TableColumn
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract.... And i'm not able to set value to a particular column. How can i do it? Please
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I there Iam a java beginner. I have to create a application where I can select a employee's name from a comboBox and the jtable will be filled with all
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
How to collect Java input field value display into Jtable?
How to collect Java input field value display into Jtable?  <p>We would like to know how to collection input field data into Jtable... as the following information. - display the value in the JTable. If in the GUI as per view
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
Create a Custom Cell Renderer in a JTable
that can be used to display the cells in a column. The JTable describes a specific... Create a Custom Cell Renderer in a JTable       After getting the knowledge about the JTable
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
jtable
jtable  i have build an application and i retrieve data from the database and store it in jtable.now i have to make a checkbox column in each row and also a select all option in header but i am not able to do so.i am getting
How To Display both image and data into Swing JTable which is retrieved from ms access database
How To Display both image and data into Swing JTable which is retrieved from ms access database  So far this is my code how can i display both image and data from database.. while (rs.next()) { Vector row = new Vector(columns
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
all sequences to create jdbc and how can i use jtable to display a single... a view in my database schema so how can i create a jtable to look the view result... ); } } catch(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane
JTable - Swing AWT
JTable  Hi Deepak, i m facing a problem with jtable. i am able to display the values from the database into the jtable. but not able to modifying multiple cell values in a row. also i want to store those modified
java jtable
in which i have to display database records in jtable .now I want to read only the values of particular row at which the jtextfield has been set. and display that in jtable. plz help me with the code
Runtime error
Runtime error  I have written 3n+1 code in java and it gives correct o/p but when i submit my code online for my contest it says runtime error.. how to know where is problem
Runtime Class
Runtime Class  How can we halt d execution withd help of exit(arg) method?? ...pls tag a code
runtime error
runtime error  still i am getting runtime error as:the specified dsn contains an architecture mismatch between the driver and application   Hi, This error is related to some OS related problem. "dsn contains
Show multiple identical rows into JTable from database
Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here... rows from database on clicking search button to jtable. The given code accepts
Advertisements
 

 

 

DMCA.com