Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pagination of a Jtable

Posted on 2007-11-16
6
Medium Priority
?
2,242 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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: …
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
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 …
Suggested Courses

636 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