-1

I have a file called Items.dat, which looks like this:

Item1
subItemA

subItemB

subItemC

Item2

subItemE

subItemR

subItemT

and etc...

Using string Tokenizer, how do I input these data into a jTable so Item 1 and Item 2 are headings, and corresponding "subItems"

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Geuni
  • 93
  • 1
  • 2
  • 12
  • There are tutorials that can help you with this, and that's where you should start. Assuming that you've done this already, please tell us what you've tried and how it's not working. Have a look [here](http://docs.oracle.com/javase/tutorial/reallybigindex.html), and search on this page for "How to Use Tables", and then click on the link. – Hovercraft Full Of Eels Mar 03 '13 at 16:55
  • What he said. Plus, are there always 3 subItems per header? – christopher Mar 03 '13 at 16:56
  • I've checked the link before, and, maybe I'm just missing it everytime but, I can't find anything similar to what I've asked here. Cooney: about the 3 subItems, no; it's varied for each heading, and it could range to something like 20 subItems. Using the Tokenizer, could I apply an if condition for the program to recognize where the end of an Item is? – Geuni Mar 03 '13 at 17:31
  • You have to read resources online. – Ariel Magbanua Mar 11 '13 at 18:39

1 Answers1

2

Here's an outline of how you might proceed:

  • As you are new, abandon the NetBeans GUI editor, implied in your previous question, but continue to use the NetBeans IDE.

  • Study the I/O Streams tutorial examples.

  • Study How to Use Tables: Creating a Table Model.

  • Following this example, write a method that reads your data file and fills in your TableModel with the String values found, e.g.

    List<String> columnNames = new ArrayList<String>();
    List<List<String>> rowData = new ArrayList<List<String>>();
    
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • The program I'm writing is Linkedlist orientated, and I know how to present the linkedlist data in an array format, but would this method work directly for a linkedlist? or only arraylists? – Geuni Mar 05 '13 at 20:17
  • By coding to the `List` interface, you are free to choose the concrete implementation that best suits your use case. – trashgod Mar 05 '13 at 21:49