Adding Object to Custom Table Model

Posted on 2004-10-28
Last Modified: 2010-03-31
I am using the below code as my custom table model.  Now, when I'm using either method .addMachine or .addMachineList, I do not get the objects to load in the table.  I know the JTable is taking the model because the column headers are being assigned.  Now, if I use my constructor which takes in a List, it still does not render the data.  Am I missing a function from the DefaultTableModel that I need to override?


      public class MachineListModel extends AbstractTableModel {
          private ArrayList datalist = new ArrayList();
          private String[] columns={"Name",
                                    "Job Number",
          public MachineListModel(){
          public MachineListModel(List l){
          public void addMachine(Machine m){
          public void addMachineList(List l){
          public Machine removeMachineAt(int row){
              Machine machine = (Machine)datalist.remove(row);
              return machine;
          public Machine getMachineAt(int row){
              return (Machine)datalist.get(row);
          public String getColumnName(int col){
              return columns[col];
          public int getRowCount() {
           return 0;

          public int getColumnCount() {
           return columns.length;

          public Object getValueAt(int row, int col) {
            Machine machine = (Machine)datalist.get(row);
                case 0:
                    return machine.getName();
                case 1:
                    return machine.getDescription();
                case 2:
                    return machine.getJobnumber();
                case 3:
                    return machine.getDepartment();
                    return null;
Question by:lomidien
    LVL 92

    Accepted Solution

    >          public int getRowCount() {
    >           return 0;
    >          }

    you aren't returning the row count.
    should be:

    return datalist.size();


    Author Comment

    Man Alive!!!  Another pair eyes are indeed a good thing.  :)  Looked right over that one.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    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 …

    884 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

    21 Experts available now in Live!

    Get 1:1 Help Now