Search code examples
javaswingjtablestringtokenizertablemodel

Java - Reading data using string tokenizer for jTable


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"


Solution

  • 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>>();