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

 
 


i m
Not able to display jtable at runtime
2 Answer(s)      2 years and 2 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();
    }

}
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 Pages:
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
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
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
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
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
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
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
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
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
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
Multi-line cells in the JTable - Java Tutorials
, asked me how to display a JTextArea within a cell of a JTable. I sensed it would...Multi-line cells in the JTable 2002-04-11 The Java Specialists' Newsletter [Issue 045] - Multi-line cells in the JTable Author: Dr. Heinz M. Kabutz
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
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
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
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add... one help me out........... I tried this problem but iam only able to display
Setting Tool Tips on Cells in a JTable
the tool tips in the cells in a JTable component. So, you will be able to know... Setting Tool Tips on Cells in a JTable   ... that is used to display the message in small box given by the user appropriate
Java JTable
Java JTable  I am create one application. The application is same as MSExcel. but the content do not modify by others. I am refer the following link. link text That work fine. But i want display content in my datatbase. If i
Shading Rows in JTable
Shading Rows in JTable       You have learnt about the JTable components and its column headers in the previous Java section. Now, you will be able to do
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 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
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
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
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
How to collect Java input field value display into Jtable?
How to collect Java input field value display into Jtable?  We would like to know how to collection input field data into Jtable with the following... rate - input interest rate text Result - Display result into Jtable Jtable
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 in java swing
jtable in java swing  hai friends... i am creating 1 GUI having 1 table, that table contain 3 fields(columns) and 10 rows.. user can enter values... should reach to 2nd row 1st column. user can not able to edit the values present
jsp directory created in net beans but not able to access
trying to display image i am not able to display i am using netbeans and using...jsp directory created in net beans but not able to access  File f = new File (config.getServletContext().getRealPath("/") + "artists/" +username
java swing (jtable)
from database and display it in jtable. import java.awt.*; import java.sql....java swing (jtable)  hii..how to get values of a particular record in jtable from ms access database using java swing in netbeans..?? please help
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 combo - Java Beginners
jtable combo  i am using jtable (using defaulttablemodel) ,when i am click on a particular cell of jtable i want to display the combo box...); JTable table = new JTable(model); TableColumnModel tcm = table.getColumnModel
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
How to create Runtime time jLabel in java swing ?
How to create Runtime time jLabel in java swing ?   hi sir. my problem is that i want to display database row on a jLabel. Suppose i retrived a table from database & i want to display its row value on jLabel. i m facing
search filter and JTable
my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont...","Contact No","Email"}; JTable table=new JTable(data,labels
problem scrolling jtable
problem scrolling jtable  hi, i've to query the table thousand of times...m table display is not getting stable/proper,especially after getting...;}}; table = new JTable(tableModel
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
JTABLE SCROLL PANE
JTABLE SCROLL PANE  The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something..., ex); } //</editor-fold> /* * Create and display the form
JTABLE SCROLL PANE
JTABLE SCROLL PANE  The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something..., ex); } //</editor-fold> /* * Create and display the form
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add... one help me out........... I tried this problem but iam only able to display
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
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
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 . Here is the person.xml file
sum of all values in a column of jtable
, is there a code to display the sum of all values in a column of a jtable namely CARTtbl... or deleted.   Here is an example of jtable that sums up the values of two columns and display the result in another column. import javax.swing.*; import
How to use JTable with MS-Access
and display it in JTable. import java.awt.*; import java.sql.*; import java.util....How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.