Results 1 to 4 of 4
  1. #1
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default From txt to JTable.

    Evening forum.

    Have a problem with my AdressBook. I need to read from txt (no problem there) split every word (no problem there). List it with JTable. (big problem).

    code to read and split
    Java Code:
    FileReader fr = new FileReader("c://java/readme.txt");
    		    BufferedReader br = new BufferedReader(fr);
    		    while ((contens = br.readLine())!=null){
    		    wsplit = contens.split(";");
                              .....
    Code to show JTable.

    Java Code:
    public class myTable extends AbstractTableModel {
    
    
    	private String[] columnNames = {"First Name",
                "Last Name",
                "Adress",
                "Post Nr",
                "Phone nr"};
    
    	private Object[][] data = {
                {"ocean", "adressbook", "Borås", "512 33", "0318111"}
                };
    What i have tryed with no succes is.

    Java Code:
    private Object[][] data = {
                {wsplit[0], wsplit[1], wsplit[2],wsplit[3], wsplit[4] }
                };
    Dont think i have to mention that im quite new to this. And I would be happy for any advice on how this could be done.I have read what there is to read about JTable on sun´s website, but cant find any information on how to add from external file.

    / Best Regards Ocean

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I would recommend that you extend DefaultTableModel and not AbstractTableModel as this is far easier to work with: it does most of the hard work for you. (Where's camickr when you need him?)

  3. #3
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Thank you again. Found helpful information at this link.

    Using JTable and DefaultTableModel

    Will come back when i solved it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. JTable
    By ivvgangadhar in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2009, 04:59 AM
  2. Jtable
    By prashant in forum Java Applets
    Replies: 0
    Last Post: 07-19-2009, 07:04 PM
  3. Regarding the JTable
    By suresh.uvce in forum AWT / Swing
    Replies: 5
    Last Post: 02-11-2009, 06:46 AM
  4. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  5. Help with JTable
    By fernando in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:57 AM

Posting Permissions

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