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!!!
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html 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=http://java.sun.com/javase/6/docs/api/]here[/url], which usually links to the Swing tutorial for common Swing components.
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.
I am having the exact same problem and making no progress. I have data stored in a text file delimited by semicolons.
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 hotmail.com. 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.
And I/O and StringTokenizer or regexes (with swingworker ofcourse).
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.
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!
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.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.