Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating JTable with AbstractTableModel

 
Kalel Lorav
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new at programming and this is my first posting on here with the hope to get the help I need to finish my first programming assignment. My JTable comes up fine the first time, but when I enter new input, the table does not update with the new data. The problem is tied with my AbstractTableModel as I just don´t know how to override methods setValueAt and getValueAt. Here is what I have done. the data to be displayed in the table ir read from arrays int nh, String hNam, int nv, String proc_1 and String proc_2. fnh is the number of rows. The table has five columns and that´s remains the same. If someone would be kind enough to correct those two methods methods I would be deeply thankful.



 
Campbell Ritchie
Sheriff
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Why does your set method apparently not alter any of the values in the model? How do you set the value anywhere?
Why are you using an array of different kinds rather than an object which encapsulates the values for a row? There is something very un‑object‑ orientated about an Object[][]. No, later on you appear to be using parallel arrays; that is even worse design.
There is also something wrong with fnh. Not only is it a poor name for a variable, but also it is tightly coupled to something in another class’ implementation. Why are you not setting that in the constructor? Why are you not passing a Horse[] array to the constructor? That can encapsulate all the information required, even including the row count, because as you already know, all arrays record how many elements they contain. And the Horse class can encapsulate its count of fields, so you don’t need to mess about with integer literals like 5.

I shall move this discussion to the GUIs forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic