Skip to main content

Jtable from netbeans gui

7 replies [Last post]
Joined: 2007-10-03

I'm new in java programming and I need help for a jtable.
I use netbeans and in a form I put a jtable, now I want to populate the rows with data from a text file but I don't succed...please help me!!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-04-17 is a tutorial for tables (but not specific creating them using Netbeans Matisse), but it might be a good idea to learn how to code a table + table model manually. You'll get a better idea what the GUI builder actually does.

The Java 6 API docs are [url=]here[/url], which usually links to the Swing tutorial for common Swing components.

Joined: 2007-11-18

Thanks Walterln for the links to the Java API and the article on using swing tables.

I'll read the article and give it a try.

Joined: 2007-11-03

I am having the exact same problem and making no progress. I have data stored in a text file delimited by semicolons.


doe, john;12;43;false;
smith, jane;9;12;true;

I have set up a gui project in NetBeans and inserted a JTable. I now want that JTable to populate it's four columns with the four fields from the text file (String, int, int, boolean).

Despite a week of looking through sparse documentation and message boards, I can find nothing to help me do this in NetBeans. I would really appreciate if anyone has any ideas.

The only online help I could find had to do with syncing databases like Access, etc with JTable. I just want the data pulled from this text file, changed by the user, and then saved back to the text file.

If you have any thoughts, ideas, suggestions, please email me at:


I am on Thanks!

I usually never ask for help, I just keep trying different things or searching other threads, but I really can't figure this out for some reason.

Joined: 2006-05-02
And I/O and StringTokenizer or regexes (with swingworker ofcourse).

Joined: 2007-11-03

Thanks for the quick response and for the link. I did go through that page earlier today and understand how to code it manually.

The problem is that I have already set up a complex GUI in the NetBeans 5.5 IDE and need to be able to make this change in there. Unfortunately, the section regarding the DefaultTableModel, etc. is protected code in NetBeans and cannot be edited manually in the source code view.

I can easily write methods to read my text file, tokenize it, and then load it into an array. The problem is: How do I let the JTable know to access that particular array for the data since it won't let me edit the code? I am sure there must be something simple I am missing regarding where to click in the design view to make the necessary change to the JTable.

Any ideas?

Joined: 2007-11-03

Okay, I figured out that part (I wrote how I did it below in case it helps someone else).

I do have another question: How do you add a JComboBox WITHIN the table? I'd like for all of the cells in the first column to have identical JComboBoxes populated with data from a text file. The user can then pick one of the choices and that choice will be displayed in the JTable and written back to the data array.



Somewhere at the top of the code view, I declared my data array.

Then, I clicked on the JTable properties, then clicked model.

I picked FormConnection from the dropdown box and then under user code I set the model and passed it the array and column headings and data types.

Then, I clicked Advanced and under PRE-initialization code, I entered the code to read the data file and load it into an array.

It works great!

Joined: 2007-11-18

Hi Ulatif,

Good. The way you got it to work is very ingenious.

However, I'm stuck getting this to work. I was able to define at the top of the class code the multi array (no initialization) for the data as well as the array with the column headings.

I see where you enter the code for the Model, but have trouble visualizing how to enter it and define the column data types as well. I thought the whole data array was just an array of objects.

Is the code to read the data from your file a code based on tokenizer and eof?

Sorry to ask and the inconvenience. I'm new at doing this stuff. Thanks in advance.

Best regards,