Not able to display jtable at runtime

Not able to display jtable at runtime

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();
    }

}
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
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
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  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
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
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
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  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
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
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
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...({}); But the tableChanged method is called recursively. And i'm not able
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
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
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
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
Create a Custom Cell Renderer in a JTable
that can be used to display the cells in a column. The JTable describes a specific... that will display in given output of table. The even rows of a JTable contains cyan... Create a Custom Cell Renderer in a JTable   
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
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
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
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
JTable Display Data From MySQL Database
JTable Display Data From MySQL Database In this section we will discuss about how to display data of a database table into javax.swing.JTable This section will describe you the displaying of data of a database table into a JTable
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
Add XML to JTable
Add XML to JTable In this section, you will learn how to access the contents or data of xml document and display its information into the jtable. Java... all the xml file data into the JTable .ADS_TO_REPLACE_1 Here is the person.xml
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container... table after clicking the row on to the jdialog box. i am not able to add
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
Jtable with servlet - Java Beginners
time I want the JTable to display the record saved in the database,the JTable... of the page and the bottom half will consists of JTable to display the record information... other way to do so.I need help to display the record in JTable with the servlet
jtable problem
jtable problem  how to make a cell text hypertext
Jbutton in JTable cells
Jbutton in JTable cells  I am a Java Beginner... I want a code in which I display data in Jtable from database and correspondingly a JButton for each cell and when i click on that button a new window should open
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
jtable query compare with date
in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code...jtable query compare with date  how to transfer daytable data
jtable query compare with date
in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code...jtable query compare with date  how to transfer daytable data
jtable query compare with date
in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code...jtable query compare with date  how to transfer daytable data
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
Swing JTable which is retrieved from MySQL
Swing JTable which is retrieved from MySQL  How To Display both image and data into Swing JTable which is retrieved from MySQL database
JTABLE Issue
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
JTable - Swing AWT
JTable  Hi Deepak, i want to display the Jtable data... how could i show jtable data on the console. Thanks, Prashant   Hi...*; public class JTableToConsole extends JFrame { public Object GetData(JTable
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example

Ads