Solved

Pagination of a Jtable

Posted on 2007-11-16
6
2,097 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 73
JavaScript/Java - Changing an image background color 4 67
login jsp example 24 51
hibernate example issues from command prompt 10 42
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

803 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