Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:53:57+00:00 2026-06-02T07:53:57+00:00

Hi I have an arraylist of a class I created called Pets which has

  • 0

Hi I have an arraylist of a class I created called Pets which has the variables below

private String name;
private String species;
private int age;

I wanted to display this arraylist into a jTable and I did that succesfully by using defaultTableModel and calling setModel().

However I needed to add a sorting and filtering function for the Jtable. I took a look at the java tutorials were they were creating a subclass of AbstractTableModel in order to sort and filter. However they were using arrays to store the data. So I tried modifying the code to use an arraylist isntead but Im stuck with this method

public Object getValueAt(int row, int col) {
    return data[row][col];
}

How do I get all the values from one object from th arraylist?

Any help will be greatly appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:53:58+00:00Added an answer on June 2, 2026 at 7:53 am

    Does your ArrayList hold a row that is it’s own type of object? If so, and if your ArrayList is a generic ArrayList<RowItem> then you could do something like:

    @Override
    public Object getValueAt(int row, int col) {
      if (row > getRowCount()) {
         // throw an exception
      }
      RowItem rowItem = rowItemList.get(row);
      switch (col) {
      case 0:
         return rowItem.getName();
      case 1:
         return rowItem.getLastSpecies();
      case 2:
         return rowItem.getAge();
      }
      return null; // or throw an exception
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist which has a class datastructure. public class empRec { public
At the moment inside the class I have ArrayList which the objects are stored
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have created a new class called Get_WebPage1 and init I have extends that
I created an arraylist in Java called rows . Now I have a text
I have a class called Places with placeId declared as Int. int placeId; I
I have created an application having tab activity which in turn has 5 different
I have a base class called Geometry from which there exists a subclass Sphere
Say I have already created an iterator called iter and an arraylist called database.
I currently have an ArrayList holding objects of a class I have created, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.