aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes creating JTable using data from .txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "creating JTable using data from .txt file" Watch "creating JTable using data from .txt file" New topic
Author

creating JTable using data from .txt file

boki markos
Greenhorn

Joined: May 10, 2009
Posts: 5
i can compile, the JTable is created and so are the column headings but the rows arent... in the rows this comes up : [Ljava.lang.String;@408fbecf <--- these numbers change on every cell
i think the problem is with the getValueAt() class... can someone please help me out.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19788
    
  20

boki markos wrote:[Ljava.lang.String;@408fbecf <--- these numbers change on every cell

That is the result of toString() called on a String[].

You probably want to return rosterList.get(row)[column] in getValueAt - rosterList.get(row) returns a String[], and you take element column of that array.

Of course you will need a cast to String[] if you're not using generics.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
boki markos
Greenhorn

Joined: May 10, 2009
Posts: 5
hey, thanks for reply... umm i am pretty new to java, what is a cast to String[]? :S

i changed

rosterList.get(row)[col] and i still get an error
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19788
    
  20

Check out http://www.janeg.ca/scjp/oper/cast.html

Because your ArrayList does not use generics, rosterList.get(row) returns an Object reference. You need to cast that to String[] first, before you can access its elements.

Or you can make your ArrayList generic; check out http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
We usually discuss this sort of question on the Swing forum. Moving.
boki markos
Greenhorn

Joined: May 10, 2009
Posts: 5
dont get that generics stuff lol

anyother way to do it?

can you show me what i need to change please?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19788
    
  20

Have you even read that first link?
boki markos
Greenhorn

Joined: May 10, 2009
Posts: 5
is this what you ment? i changed my ArrayList... the program now compiles and runs but no rows.. just the headings(columns)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19788
    
  20

That's from the second link, but to be honest, generics are better.

What are the contents of rosterList? Is the file read properly?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating JTable using data from .txt file