Solved

Pagination of a Jtable

Posted on 2007-11-16
6
2,082 Views
Last Modified: 2013-11-23
I need some assistance with a jtable.  I have a panel that displays a jtable and the jtable is displaying the first 100 records.  I need to implement pagination but not sure how to go about it.  I want to have a next and previous button and just display 100 records at a time.  Right now there are only about 400 records but it will probably grow in the future.  So far I programmed one button and it returns 100 records but it appends it on to the existing table and I am not sure how to not do that. I found an article on JavaWorld about pagination but it wasnt working for me.  Any suggestions?  Thanks.
0
Comment
Question by:bolts123
  • 3
  • 3
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 20301467
you need to either clear your model before adding new rows, or create a new one
0
 

Author Comment

by:bolts123
ID: 20301689
I tried clearing the model, I tried repainting and revalidating the table and creating a new one and it doesn't  help.  I am probably doing it wrong since I am fairly new at using jtables.  Could you give me an example?
0
 
LVL 92

Expert Comment

by:objects
ID: 20301735
post the code that loads the next page and i'll check what ur doing wrong
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:bolts123
ID: 20301788
public void nextRecords()
      {      
            
            testTableModel = new DefaultTableModel();
            testTable.repaint();
            testTable.revalidate();
            
            
            String base = getAddress()+
            getfirstName() + "&" +
            getLastName()+ "&" +
            getPageOffset();
            xmlDoc(base);
            
               
            String[][] Table = getTable("info");
            Object[] Column = new Object[Table.length];
            
            
            
        
            if(Table.length > 0)
            {      
            for(int i = 0; i < headers.length; i++)
            {
            for(int j = 0; j < Table.length ; j++)
            {
                  if(headersi] == 8 || headers[i] == 9)
                  {
                        Column[j] = Table[j][headers[i]].substring(0, 10);
                  }
                  else
                  {
                        Column[j] = Table[j][headers[i]];
                  }
            }
                  
                  testTableModel.addColumn(columnNames[headers[i]], Column);
                  
                  fireTableDataChanged();
                  
                                                      
            }
                  
                  
      }
      
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 20301811
public void nextRecords()
      {      
           
            testTableModel = new DefaultTableModel();
             String base = getAddress()+
            getfirstName() + "&" +
            getLastName()+ "&" +
            getPageOffset();
            xmlDoc(base);
           
               
            String[][] Table = getTable("info");
            Object[] Column = new Object[Table.length];
           
           
           
       
            if(Table.length > 0)
            {      
            for(int i = 0; i < headers.length; i++)
            {
            for(int j = 0; j < Table.length ; j++)
            {
                  if(headersi] == 8 || headers[i] == 9)
                  {
                        Column[j] = Table[j][headers[i]].substring(0, 10);
                  }
                  else
                  {
                        Column[j] = Table[j][headers[i]];
                  }
            }
                 
                  testTableModel.addColumn(columnNames[headers[i]], Column);
                                                     
            }
                 
          testTable.setModel(testTableModel);          
      }
0
 

Author Comment

by:bolts123
ID: 20301875
That worked.  Thanks.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Non-recursive backtracking, using a stack 1 103
advertisement module in core php 4 145
mockito example issue 8 62
Recommendation vb6 to vb.net or others 14 112
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now