Some error in setting table model to a JTable..kindly help..

hi all,
i m pasting a code of a function in which i fetch data from the database n display it in a JTable pasted on a panel in a JFrame window.
There is some problem with the table model which i m unable to correct.
Kindly help..
public void showDetails(){
     Statement statement;
     ResultSet rs;
Connection connection;
     //DATABASE CONNECTION
          try{
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          connection=DriverManager.getConnection("jdbc:odbc:iirsdb");
               statement=connection.createStatement();
               String strQuery=null;
               Object[][] data;
               //SELECT QUERIES
                    if(index>=1 && index<=14)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblStatic where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
                    if(index>17 && index<=22)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblSemiDyn where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
                    if(index==25)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblDyn where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
               rs=statement.executeQuery(strQuery);
               ResultSetMetaData rsmd=rs.getMetaData();
               int col=rsmd.getColumnCount();
               Vector colNames=new Vector();
               Vector row=new Vector();
               for(int i=1;i<=col;i++){
                    colNames.addElement(rsmd.getColumnName(i));
               while(rs.next()){
                    for(int i=1;i<=col;i++){
                         row.addElement(rs.getObject(i));
                    data.addElement(row);
               DefaultTableModel tableModel = new DefaultTableModel(data, colNames);
               JTable table= new JTable(tableModel);
               //table.setModel(new DefaultTableModel(data,colNames));
               //JTable.revalidate();
               //display table with ResultSet contents
                         //JTable table= new JTable(row, colNames);
                         JScrollPane scroller=new JScrollPane(table);
                         pnlFifth.add(scroller,BorderLayout.CENTER);
                         scroller.setVisible(true);
                         scroller.validate();
               rs.close();
}catch(ClassNotFoundException cnfex){
               System.err.println("Failed to load JDBC/ODBC driver");
               cnfex.printStackTrace();
catch (SQLException sql){
JOptionPane.showMessageDialog(this, "Cannot connect to Database"+sql,"Error", JOptionPane.WARNING_MESSAGE);
}

hi..okays..will take care of this..actually, this ws d first time i ws using this community service.
Below.i inserted checkstatements but still d table isnt getting displayed..wht to do? D logic is correct i guess but whr is d problem?
public void showDetails(){
     Statement statement;
     ResultSet rs;
    Connection connection;
    Vector colNames=null;
         Vector data=null;
     //DATABASE CONNECTION
          try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                connection=DriverManager.getConnection("jdbc:odbc:iirsdb");
               String strQuery=null;
          data = new Vector();
               //SELECT QUERIES
                    if(index>=1 && index<=14)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblStatic where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
                    if(index>17 && index<=22)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblSemiDyn where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
                    if(index==25)
                         strQuery="select IP_Address,"+strMapped+",Timestamp from tblDyn where IP_Address='" + strIP + "' and Timestamp='"+strTime+"' and "+strMapped+"='"+strDetailResult+"'";
               statement=connection.createStatement();
               rs=statement.executeQuery(strQuery);
               ResultSetMetaData rsmd=rs.getMetaData();
               int col=rsmd.getColumnCount();
               //int r=rsmd.getRowCount();
               colNames=new Vector();
               for(int i=1;i<=col;i++){
                    colNames.addElement(rsmd.getColumnName(i));
               while(rs.next()){
                    Vector row=new Vector(col);
                    for(int i=1;i<=col;i++){
                         row.addElement(rs.getObject(i));
                    data.addElement(row);
               rs.close();
               statement.close();
}catch(ClassNotFoundException cnfex){
               System.err.println("Failed to load JDBC/ODBC driver");
               cnfex.printStackTrace();
catch (SQLException sql){
            JOptionPane.showMessageDialog(this, "Cannot connect to Database"+sql,"Error", JOptionPane.WARNING_MESSAGE);
JTable table=new JTable(data,colNames)
            public Class getColumnClass(int column)
                for (int row = 0; row < getRowCount(); row++)
                    Object o = getValueAt(row, column);
                    if (o != null)
                        return o.getClass();
                return Object.class;
        JScrollPane scrollPane = new JScrollPane( table );
        //getContentPane().add( scrollPane );
        pnlFifth.add( scrollPane );
        scrollPane.setVisible(true);
}     

Similar Messages

  • HT3743 hi i wanna restore my iphone3g but some error 1015 comes out,what will i do,pls help me.thanks!!!

    hi,i wanna restore my iphone3g but some error 1015 occured,what will i do,pls help me...thank u!

    Per Terms of Service to which you agreed when you joined
    this forum, discussion of jailbroken iPhones is prohibited.
    Google may provide some assistance, but it is just as likely
    that the jailbreak has permanently damaged your iPhone.

  • Error message setting up Yahoo email account...help!

    I just got my new Droid Razr yesterday, and I have tried numerous times to set up my existing Yahoo email account but I keep getting an error message that states "System is unavailable to support the request". My email address and password are correct, I am able to log in just fine on my computer, so I can't figure out what the problem is or how to fix it. Any help would be appreciated!

    Try this under the settings:
    Yahoo Ymail: IMAP
    Incoming Settings:
    Username: [email protected]
    Password: (check the case for your password)
    IMAP server: imap.mail.yahoo.com
    Port: 143
    Security type: TLS if available
    IMAP path prefix: (leave blank, it should read "Optional"
    Outgoing Settings:
    SMTP server: smtp.mobile.mail.yahoo.com
    Port: 25
    Security type: TLS if available
    Require sign-in: Checked
    Username: [email protected])
    Password: (check the case for your password)
    If that does not work, I would use the app available in the Play Store as stated above.

  • HT204370 I cannot watch a downloaded HD quality movie on my Sony Bravia LED TV connected by HDMI or VGA. I get some error stating something about High resolution. Can anyone help?

    I am unable to watch a HD quality movie I purchased on Itunes store, cannot watch connecting my Laptop (Ultrabook) to Sony Bravia LED. I get some message stating HD quality is not compatiable.
    Can any one help solve this?
    Otherwise it is useless to buy movies from Itunes store.
    Rajan

    Hi rbeeez,
    If you are having issues playing back HD video from the iTunes Store on an external display, you may find the following articles helpful:
    iTunes: Purchasing and viewing HD videos
    http://support.apple.com/kb/ht3209
    iTunes for Windows: Unable to view or play HD video content that requires HDCP
    http://support.apple.com/kb/ts3354
    Regards,
    - Brenden

  • Error while setting the SSL with trusted cert --  any help on this?

    Connecting to Node Manager ...
    <Aug 3, 2010 5:20:17 PM CDT> <Warning> <Security> <BEA-090542> <Certificate chai
    n received from localhost - 127.0.0.1 was not trusted causing SSL handshake fail
    ure. Check the certificate chain to determine if it should be trusted or not. If
    it should be trusted, then update the client trusted CA configuration to trust
    the CA certificate that signed the peer certificate chain. If you are connecting
    to a WLS server that is using demo certificates (the default WLS server behavio
    r), and you want this client to trust demo certificates, then specify -Dweblogic
    .security.TrustKeyStore=DemoTrust on the command line for this client.>
    This Exception occurred at Tue Aug 03 17:20:18 CDT 2010.
    javax.net.ssl.SSLKeyException: [Security:090542]Certificate chain received from
    localhost - 127.0.0.1 was not trusted causing SSL handshake failure. Check the c
    ertificate chain to determine if it should be trusted or not. If it should be tr
    usted, then update the client trusted CA configuration to trust the CA certifica
    te that signed the peer certificate chain. If you are connecting to a WLS server
    that is using demo certificates (the default WLS server behavior), and you want
    this client to trust demo certificates, then specify -Dweblogic.security.TrustK
    eyStore=DemoTrust on the command line for this client.
    at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireException(Unknow
    n Source)
    at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireAlertSent(Unknow
    n Source)
    at com.certicom.tls.record.handshake.HandshakeHandler.fireAlert(Unknown
    Source)
    at com.certicom.tls.record.handshake.HandshakeHandler.fireAlert(Unknown
    Source)
    at com.certicom.tls.record.handshake.ClientStateReceivedServerHello.hand
    le(Unknown Source)
    at com.certicom.tls.record.handshake.HandshakeHandler.handleHandshakeMes
    sage(Unknown Source)
    at com.certicom.tls.record.handshake.HandshakeHandler.handleHandshakeMes
    sages(Unknown Source)
    at com.certicom.tls.record.MessageInterpreter.interpretContent(Unknown S
    ource)
    at com.certicom.tls.record.MessageInterpreter.decryptMessage(Unknown Sou
    rce)
    at com.certicom.tls.record.ReadHandler.processRecord(Unknown Source)
    at com.certicom.tls.record.ReadHandler.readRecord(Unknown Source)

    Go through this link
    http://weblogic-wonders.com/weblogic/2010/03/03/ssl-exceptions-in-admin-server-and-node-manager/

  • An interesting problem in emp table of scott/tiger schema, kindly help

    I want to write SQL which can give me the result in columns
    ENAME, EMPNO, DEPTNO, DEPT_WISE_PCT_OF_EMP_SAL,
    CMP_WISE_PCT_OF_EMP_SAL
    i write a sql by using multiple select statements like
    select ename, ename, emp.deptno, sal, (sal/a.cmp_sal )*100 cmp_sal_pct, (sal/dept_sal.dept_sal)*100 dept_sal_pct
    from emp, (select sum(sal) cmp_sal from emp) a,
    (select deptno, sum(sal) dept_sal from emp group by deptno) dept_sal
    where dept_sal.deptno = emp.deptno
    ENAME ENAME DEPTNO SAL CMP_SAL_PCT DEPT_SAL_PCT
    CLARK CLARK 10 2450 8.4409991386736 28
    KING KING 10 5000 17.226528854436 57.142857142857
    MILLER MILLER 10 1300 4.4788975021533 14.857142857143
    SMITH SMITH 20 800 2.7562446167097 7.3563218390805
    ADAMS ADAMS 20 1100 3.7898363479759 10.114942528736
    FORD FORD 20 3000 10.335917312661 27.586206896552
    SCOTT SCOTT 20 3000 10.335917312661 27.586206896552
    JONES JONES 20 2975 10.249784668389 27.35632183908
    ALLEN ALLEN 30 1600 5.5124892334195 17.021276595745
    BLAKE BLAKE 30 2850 9.8191214470284 30.31914893617
    MARTIN MARTIN 30 1250 4.306632213609 13.297872340426
    JAMES JAMES 30 950 3.2730404823428 10.106382978723
    TURNER TURNER 30 1500 5.1679586563307 15.957446808511
    WARD WARD 30 1250 4.306632213609 13.297872340426
    but i want to solve this problem using single sql
    i write the required sql but i unable to get the salary on company basis(total sal of all emp)
    select emp.ename, emp.deptno, emp.empno, emp.sal,
    (emp.sal/sum(dept_emp.sal))*100 dept_sal_pct
    from emp, emp dept_emp
    where emp.deptno = dept_emp.deptno
    group by emp.ename,emp.deptno, emp.empno, emp.sal
    ENAME DEPTNO EMPNO SAL DEPT_SAL_PCT
    CLARK 10 7782 2450 28
    KING 10 7839 5000 57.142857142857
    MILLER 10 7934 1300 14.857142857143
    ADAMS 20 7876 1100 10.114942528736
    FORD 20 7902 3000 27.586206896552
    JONES 20 7566 2975 27.35632183908
    SCOTT 20 7788 3000 27.586206896552
    SMITH 20 7369 800 7.3563218390805
    ALLEN 30 7499 1600 17.021276595745
    BLAKE 30 7698 2850 30.31914893617
    JAMES 30 7900 950 10.106382978723
    MARTIN 30 7654 1250 13.297872340426
    TURNER 30 7844 1500 15.957446808511
    WARD 30 7521 1250 13.297872340426
    thanks in advance

    Try this (untested)
    select ename, ename, emp.deptno, sal,
      RATIO_TO_REPORT(sal) OVER ()*100 cmp_sal_pct,
      RATIO_TO_REPORT(sal) OVER (PARTITION BY dept)*100 dept_sal_pct
    from empRATIO_TO_REPORT is the key. If this doesn't work then check the docs.

  • Error in the table parameter.

    Hi All,
    I have some Error in a table parameter in the tree model when i created the Dialog program.
    "Errors : ITEM_TABLE contains two items with the same name"
    Please help me to solve this error
    Regards,
    Luke

    Hi,
    As per Data given
    the item_table you created must be having the same field name twice
    (1) eg: imagine if you declared
    item_table type table of ZXXXX
    Check in se11,in the column "Fields" if any field is repeated but if you check syntax,then errror message will be displayed
    or data base inconsistency in activation will come
    (2) if you have declared it as
    data : begin of XXXX
    then you must have repeated a field name by mistake like
    data : begin of XXXX
             field1 type aXXX
             field1 type aXXXX
            end of XXXX
    or in the abap editor double click on item_table , it will take you to its declaration,just check the 2 cases mentioned above
    Pls check and revert
    Regards
    Byju

  • Table Model:: Null Pointer Exception

    I have made an application wherein I am using a JTree to display some hierarchy.
    Now while scrolling the tree,I display the details in the table.
    Data for both the components come from the database.If I continously scroll up and down for some time
    in the Tree I get an error in the Table Model
    rsmd=rs.getMetaData();
    for the above line.It throws NullPointerException,it only happens after scrolling for some time and
    not for any particular value.
    I update the table model using jtable.setModel().
    Plz help.

    What is actually throwing the NullPointerException? rs.getMetaData() or table.setModel()?

  • Error while creating table "EDISEGMENT' entry 'BIC/CIBA0PLANT_ATTR

    While loading master data for 0PLANT, its giving me following error.
    "error while creating table "EDISEGMENT' entry 'BIC/CIBA0PLANT_ATTR"
    Please help me out.
    Thanks

    steve,
    Can you give the solution you used to correct this problem?
    This error occurred in BW during import.
    Raj.

  • Uploading image file using tcode se78  occuring some   Error

    Hai Gurus
          I am uploading image file using tcode se78 but while Uploading it giving some error i cant resolve the problem so any one help me plz
    Error    "Graphic LOGO could not be saved (2LOGO)"
    Regards
    Selvendran

    Hai
    Thanks
    I had done in all method but i can't save it 
    error is coming ..so plz help me to upload the image
    Error "Graphic LOGO could not be saved (2LOGO)"
    Regards
    Selvendran

  • A question about table model

    I created a table model and use JTable to display content of a database's table with that model.
    The problem is: when I update a data to data1 in a cell (first column) and hightlight another cell (second column), all cells of first column change content to data1. What 's the problem with my table model?
    import java.util.Vector;
    import java.sql.*;
    import javax.swing.table.AbstractTableModel;
    public class CommonTableModel extends AbstractTableModel {
    String[] columnNames;
    Vector          rows, newRow;
    ResultSetMetaData metaData;
    private boolean editable;
    public CommonTableModel(ResultSet rs, boolean editable) {
    this.editable = editable;
    try {
    metaData = rs.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    columnNames = new String[numberOfColumns];
    for(int column = 0; column < numberOfColumns; column++) {
    columnNames[column] = metaData.getColumnName(column+1);
    rows = new Vector();
    newRow = new Vector();
    while (rs.next()) {
    for (int i = 1; i <= getColumnCount(); i++) {
         newRow.addElement(rs.getObject(i));
    rows.addElement(newRow);
    } catch (SQLException ex) { System.err.println(ex);}
    public int getColumnCount() { return columnNames.length; }
    public int getRowCount() { return rows.size();}
    public String getColumnName(int column) { return columnNames[column];}
    public Object getValueAt(int row, int column) {
         newRow = (Vector)rows.elementAt(row);
         return newRow.elementAt(column);
    public Class getColumnClass(int column) {
         return getValueAt(0, column).getClass();
    public boolean isCellEditable(int row, int column) {
         if (column == 0) { return false; }
         return editable;
    public void setValueAt(Object value, int row, int column) {
         newRow = (Vector)(rows.elementAt(row));
         newRow.setElementAt(value, column);
         fireTableCellUpdated(row, column);
    }

    Try this :
    rows = new Vector();
    //newRow = new Vector();
    while (rs.next()) {
        newRow = new Vector(); // it must be here
        for (int i = 1; i <= getColumnCount(); i++) {
            newRow.addElement(rs.getObject(i));
        rows.addElement(newRow);
    }Denis

  • Error  : Unicode setting doesnot match source system in BW

    Hi All,
    While replication data in BW  im facing the following error :
    unicode setting doesnot match source system.
    Kindly suggest.
    Regards,
    Amit Miglani.

    Hi,
    We have installed a fresh BIW server on MSSQL database 2005. We have selected components like as ABAP.JAVA,EP,EP Core ,BI Java. While replicating the datasource using tcode RSA1 from R/3 Retail Server we are getting an error Error in module RSQL of the datasource inter face .
    Details of Support package level-:
    SAP_ABA 700 0016 SAPKA70016 Cross-Application Component
    SAP_BASIS 700 0016 SAPKB70016 SAP Basis Component
    PI_BASIS 2006_1_700 0007 SAPKIPYM07 Basis Plug-In (PI_BASIS) 2006_1_700
    SAP_BW 700 0018 SAPKW70018 SAP NetWeaver BI 7.0
    BI_CONT 703 0008 SAPKIBIIP8 Business Intelligence Content
    Please suggest us the solution.
    Note: we are not getting any dump in st22. we have already checked the note 1162821
    Regards,
    Amit Miglani.

  • PageUp/PageDown By using Default Table Model

    Hi all,
    iam using Default Table model for my jtable i want to do pageup and pagedown operation .
    TableColumnModel cm1 = new DefaultTableColumnModel();
    DefaultTablemodel md = new DefaultTableModel(row,col);
    JTable t = new JTable(md,cm1);
    i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

    Hi,
    could you please avoid double posting:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=566380&tstart=0&trange=15
    especially with different subjects.
    It considerably reduces the overall efficiency as people will try to
    help you while the answer could already have been given in the another thread.
    If you want to push up the stack your message, reply to it,
    post more code, list the ideas that you've envisaged and so on.
    regards.

  • JTable Problem(Default Table Model)

    Hi all,
    iam using Default Table model for my jtable i want to do pageup and pagedown operation .
    TableColumnModel cm1 = new DefaultTableColumnModel();
    DefaultTablemodel md = new DefaultTableModel(row,col);
    JTable t = new JTable(md,cm1);
    i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

    sample code :
    // PagingModel.java
    // A larger table model that performs "paging" of its data. This model reports a
    // small number of rows (e.g., 100 or so) as a "page" of data. You can switch pages
    // to view all of the rows as needed using the pageDown( ) and pageUp( ) methods.
    // Presumably, access to the other pages of data is dictated by other GUI elements
    // such as up/down buttons, or maybe a text field that allows you to enter the page
    // number you want to display.
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class PagingModel extends AbstractTableModel {
    protected int pageSize;
    protected int pageOffset;
    protected Record[] data;
    public PagingModel( ) {
    this(10000, 100);
    public PagingModel(int numRows, int size) {
    data = new Record[numRows];
    pageSize = size;
    // Fill our table with random data (from the Record( ) constructor).
    for (int i=0; i < data.length; i++) {
    data[i] = new Record( );
    // Return values appropriate for the visible table part.
    public int getRowCount( ) { return Math.min(pageSize, data.length); }
    public int getColumnCount( ) { return Record.getColumnCount( ); }
    // Work only on the visible part of the table.
    public Object getValueAt(int row, int col) {
    int realRow = row + (pageOffset * pageSize);
    return data[realRow].getValueAt(col);
    public String getColumnName(int col) {
    return Record.getColumnName(col);
    // Use this method to figure out which page you are on.
    public int getPageOffset( ) { return pageOffset; }
    public int getPageCount( ) {
    return (int)Math.ceil((double)data.length / pageSize);
    // Use this method if you want to know how big the real table is. You could also
    // write "getRealValueAt( )" if needed.
    public int getRealRowCount( ) {
    return data.length;
    public int getPageSize( ) { return pageSize; }
    public void setPageSize(int s) {
    if (s == pageSize) { return; }
    int oldPageSize = pageSize;
    pageSize = s;
    pageOffset=(oldPageSize * pageOffset) / pageSize;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed event (all rows).
    public void pageDown( ) {
    if (pageOffset < getPageCount( ) - 1) {
    pageOffset++;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed (all rows).
    public void pageUp( ) {
    if (pageOffset > 0) {
    pageOffset--;
    fireTableDataChanged( );
    // We provide our own version of a scrollpane that includes
    // the Page Up and Page Down buttons by default.
    public static JScrollPane createPagingScrollPaneForTable(JTable jt) {
    JScrollPane jsp = new JScrollPane(jt);
    TableModel tmodel = jt.getModel( );
    // Don't choke if this is called on a regular table . . .
    if (! (tmodel instanceof PagingModel)) {
    return jsp;
    // Go ahead and build the real scrollpane.
    final PagingModel model = (PagingModel)tmodel;
    final JButton upButton = new JButton("Up");
    upButton.setEnabled(false); // Starts off at 0, so can't go up
    final JButton downButton = new JButton("Down");
    if (model.getPageCount( ) <= 1) {
    downButton.setEnabled(false); // One page...can't scroll down
    upButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageUp( );
    // If we hit the top of the data, disable the Page Up button.
    if (model.getPageOffset( ) == 0) {
    upButton.setEnabled(false);
    downButton.setEnabled(true);
    downButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageDown( );
    // If we hit the bottom of the data, disable the Page Down button.
    if (model.getPageOffset( ) == (model.getPageCount( ) - 1)) {
    downButton.setEnabled(false);
    upButton.setEnabled(true);
    // Turn on the scrollbars; otherwise, we won't get our corners.
    jsp.setVerticalScrollBarPolicy
    (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    jsp.setHorizontalScrollBarPolicy
    (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    // Add in the corners (page up/down).
    jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton);
    jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton);
    return jsp;
    // Record.java
    // A simple data structure for use with the PagingModel demo
    class Record {
    static String[] headers = { "Record Number", "Batch Number", "Reserved" };
    static int counter;
    String[] data;
    public Record( ) {
    data = new String[] { "" + (counter++), "" + System.currentTimeMillis( ),
    "Reserved" };
    public String getValueAt(int i) { return data[i]; }
    public static String getColumnName(int i) { return headers[i]; }
    public static int getColumnCount( ) { return headers.length; }
    class PagingTester extends JFrame {
    public PagingTester( ) {
    super("Paged JTable Test");
    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    PagingModel pm = new PagingModel( );
    JTable jt = new JTable(pm);
    // Use our own custom scrollpane.
    JScrollPane jsp = PagingModel.createPagingScrollPaneForTable(jt);
    getContentPane( ).add(jsp, BorderLayout.CENTER);
    public static void main(String args[]) {
    PagingTester pt = new PagingTester( );
    pt.setVisible(true);
    }

  • Difference between table and table model

    From what I've understood till now, in a JTable, the table itself is actually only a "display area" while the actual data is located in the table model. Is this correct?
    Does this mean it is possible to delete rows and columns within the table itself without affecting the actual data in the table model?

    Hi,
    ok, I will try to answer your second question "is it possible to delete rows and columns in the table but not in the table model"?
    The table - lets say the table's view - reflects the data of the data model only, if you fire the correct notification messages via the TableModelListener interface - JTable itself is a TableModelListener and updates its display accordingly to these messages - it never holds data by itself - if something is to be redrawn in the view, JTable ask the model via getValueAt(...) for the data and renders it using one of the cellrenderers delivered by the column of the column model resp. one of the registered default renderers.
    Now to your question - you can't delete a row in the tables view, without any change in the table model, as so the data isn't hold by the table's view, it is only held by the table model. But the other way round, it is possible - often accidentially - you can change the data in the table model and forget to fire a notification message for it via the TableModelListener interface - in this case, JTable will not update its view - and the table may look strange, if parts of its view is hidden by other applications and afterwards redrawn, when this application closes. Only the parts, that were hidden, will be redrawn - and this is done with the new data. So, keep track of always sending the correct notification message with every change you make in the table model, so that JTable is able to keep its view up to date.
    Hope this helps
    greetings Marsian

Maybe you are looking for