Results 1 to 2 of 2
  1. #1
    techwiz is offline Member
    Join Date
    Feb 2011
    Rep Power

    Question Creating Jtable and reading a txt file of numerical data


    I am very new to java and netbeans.

    I have problem with in making jtable read a txt file with numerical data.

    The txt file contains the data in following format.
    title1 title2 title3 title4 title5
    123 123 123 123 123
    . . . . .
    . . . . .
    I created jtable but dont know how to write code for making this data read by the jtable. the data is very huge...

    This Assignment is to be made in NETBEANS RCP.

    After making the data read by the jtable I have to use jfree chart to create graph for 1st column vs 2nd column, 1st column vs 3rd column and so on..

    Please any one kindly help me...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    One possible solution is to read the title data into a vector of objects, Vector<Object>, and then read each row of numeric data into another Vector<Object>. Each row of data should then be placed in a vector of vectors, Vector<Vector<Object>>. Then have a look at the DefaultTableModel API and you'll see constructor that uses two Vectors as parameters. Create a new DefaultTableModel with the two Vector's you've created above, and then insert this model into your JTable using the table's setModel method.

    I would first try to do this with hard-coded data and not worry about reading in from a file in the beginning. Create a small application that just creates the DefaultTableModel, places it in a JTable, and displays the JTable, perhaps as simply as putting it in a JOptionPane. Then if you get stuck trying this, show us your small code and any errors, and we can better be able to help you.
    Much luck!

Similar Threads

  1. Reading from file and adding to JTable
    By purple in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 11:33 PM
  2. Reading Numerical Data
    By tyang in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 04:19 AM
  3. Replies: 0
    Last Post: 11-24-2009, 02:49 PM
  4. Reading data to file
    By puk284 in forum Advanced Java
    Replies: 1
    Last Post: 04-28-2009, 04:19 PM
  5. Replies: 6
    Last Post: 12-12-2008, 04:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts