Solved

Pagination of a Jtable

Posted on 2007-11-16
6
2,065 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
Comment Utility
you need to either clear your model before adding new rows, or create a new one
0
 

Author Comment

by:bolts123
Comment Utility
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
Comment Utility
post the code that loads the next page and i'll check what ur doing wrong
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:bolts123
Comment Utility
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
Comment Utility
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
Comment Utility
That worked.  Thanks.  
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

762 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

12 Experts available now in Live!

Get 1:1 Help Now