File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes I don't understand why my JTable will not display data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "I don Watch "I don New topic
Author

I don't understand why my JTable will not display data

Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
I believe a good starting point will be to look at my table model.
As long as the list being passed to the constructor is ok,
shouldn't this work?


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

It should work... assuming the model for your JTable is an instance of this class, and assuming that instance was created with a non-empty list. And probably assuming several other things which don't come to mind because you didn't show us that code.

How about creating a short but compilable example which demonstrates your problem? Let's see... a JTable, a CarrierTableModel, a List with one entry, put it all in a JFrame, should come in at under 50 lines of code.
Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
Here is the UI.

Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
The list implementation seems to work okay. I tested via sending output ot standard out.
For some reason I can't get it in my head where to load the list from file ect.

Here is the file that retrieves the data from file.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

I should have mentioned that your example should be self-contained. That example, if I were to try it, would fail to compile because it refers to some other class. And I'm guessing that even if I had that other class, it would fail to run because it requires reading from some file.

So your example is too complicated. Simplify it by removing all the buttons (they are irrelevant). Simplify it by removing the code which reads from a file and just use code which creates one object from hard-coded data and adds that to the list.
Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
>> So your example is too complicated. Simplify it by removing all the buttons (they are irrelevant). Simplify it by removing the code which reads from a file and just use code which >> creates one object from hard-coded data and adds that to the list.

Okay, but It might take me a day or two. I do this while I work--well, in between work.

Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
Reviesed UI, now I get one row of blank cells.


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7


Although I doubt the above line is the problem (since the table has not yet been created), when working with models updates should be done to the "model" not the "list" structre that was used to create the model. So get in the habbit of using:



This will ensure that the model notifies the table of the changes.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour (as has already been suggested).

And there is a Swing forum, did you not notice the moderator moved one of your previous postings?
Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
Okay, and thanks. I'll be sure to post to the appropriate forum next time.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

And a moderator moved this one as well


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I don't understand why my JTable will not display data
 
Similar Threads
Refreshing a window
? JTable getColumnName
Concerning Custom Table Model
JTextfield data in JTable row
? File I/O (and-or) for each loop