my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Populating JTable from a textfile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Populating JTable from a textfile" Watch "Populating JTable from a textfile" New topic

Populating JTable from a textfile


Joined: Feb 05, 2007
Posts: 2
Hi All,
I have some questions. Which are,
1. I am going to read from a text file, one line at time,(may be may not be) and store the content in a Vector. Then a part of the line(not the whole line)
1.1 Separated by a specified delimeter
1.2 Not Seperated by a specified delimeter
will be shown in each JTable cell.
I have tried this,but the whole line is coming in a single cell. How to avoid this ?
And how to fetch the data for each cell, from the text line when there is no specified delimeter(In this case, "space/Tab" is the delimeter). In JTable I have used DefaultTableModel(each row is vector of Vectors)

2.Is it fine to use DefaultTableModel as my JTable model, for the type of operation that I am going to perform ? If yes, how if no Why ?

Hope to get help from you.
Please explain with example code

Thanking you
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Please explain with example code

first explain the problem with actual code

it takes a lot less time to add a line (or fix a line) to posted code
than it does to build a gui to 'requirements'
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

"neojava java", welcome to JavaRanch.

We're friendly people here, but we do require members to have valid display names.

Display names must contain your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names will be deleted.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753


Your name still does not conform to our naming policy. Please correct it right away. This is your second warning.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Populating JTable from a textfile
It's not a secret anymore!