Solved

Pagination of a Jtable

Posted on 2007-11-16
6
2,164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

691 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