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

x
?
Solved

Adding Object to Custom Table Model

Posted on 2004-10-28
2
Medium Priority
?
193 Views
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?

Thanks,
David

      public class MachineListModel extends AbstractTableModel {
          private ArrayList datalist = new ArrayList();
          private String[] columns={"Name",
                                    "Description",
                                    "Job Number",
                                    "Dept"};
                                   
          public MachineListModel(){
             
          }
         
          public MachineListModel(List l){
              datalist.addAll(l);
          }
         
          public void addMachine(Machine m){
              datalist.add(m);
              fireTableDataChanged();
          }
         
          public void addMachineList(List l){
              datalist.addAll(l);
              fireTableDataChanged();
          }
         
          public Machine removeMachineAt(int row){
              Machine machine = (Machine)datalist.remove(row);
              fireTableDataChanged();
              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);
            switch(col){
                case 0:
                    return machine.getName();
                case 1:
                    return machine.getDescription();
                case 2:
                    return machine.getJobnumber();
                case 3:
                    return machine.getDepartment();
                default:
                    return null;
            }
          }
}
0
Comment
Question by:lomidien
[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
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12440637
>          public int getRowCount() {
>           return 0;
>          }

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

return datalist.size();

0
 

Author Comment

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

Thanks,
David
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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