JTable


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: JTable

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    10

    JTable

    Hi. I'm having trouble with adding info that is in an array, in a JTable. I create a JTable:

    Code:
    	Vector rows = new Vector();
    	Vector columns = new Vector();
    	JTable table = new JTable(rows, columns);
    	JScrollPane scrollpane = new JScrollPane(table);
    Then, in some method, i add headers to the table:
    Code:
    		columns.add("Header1");
    		columns.add("Header2");
    		columns.add("Header3");
    The prolem is to add info to the rows, as it's read from a file, and placed in an array: read lines from file, separate them by " ", and place each string in an array[i]. How can i get the info in array[i] inside the rows in the table? sorry for my bad explanation... ask if u don't understand what i mean

  2. #2
    Join Date
    Sep 2004
    Posts
    103
    Trying to Create an array of Columns?
    int i = 0;

    // inside action listener
    String [] Columbs {"Header1", "header2", Header3"}
    Create a Array of Rows?
    Object [] row = {strings, strings, strings};
    data[i] = row;
    // finished action listener

    // insde where you create table

    // sets up 50 blank rows
    Object [] row = {" ", " ", " ", " "," "," ", " ",""};
    for (int k=0; k<50; k++) data[k] = row;

    Then call
    table = new JTable(data, columns);
    this help?

  3. #3
    Join Date
    Apr 2005
    Posts
    10
    The porblem is, that i'm reading the info that goes into the table from a file. i dont know the lenght of this file, nor do i know the contents. so i cant use static declared row contents. I'm reading from the file, then places the strings into an array. I need to put the contents of the array int the rows..

  4. #4
    Join Date
    Apr 2005
    Posts
    12
    have fun, I recently was developing an application that at the time was using a JTable. The application, like yours, instantiated from a file. What I did was read in all the data and put it into a data structure, then evaluate the size of the data structure. I did however know how many columns would be needed ahead of time. So I created the table and used setValueAt() for specific cells. If this doesn't work because you are placing some manner of Object (other than Strings) into the table let me know and I can discuss this further.

    In conclusion I hate JTable it doesn't work well for a lot of things and I had to abandon it in the end. Can I ask what functionality will be required of the table once you get your information into it?

  5. #5
    Join Date
    Mar 2004
    Posts
    635
    Are you asking how to add elements (rows) to a table with an unknown length? Or how to retrieve the value at a specific row? Anyhow, I would use a TableModel for your JTable.

    http://java.sun.com/docs/books/tutor...nts/table.html

  6. #6
    Join Date
    Apr 2005
    Posts
    10
    No other functoinality is required, than printing out the contents of a file: a date, some strings, and some more strings. The first integers are ok, i read them from the file and store them in a variable. the strings are not ok, cuz i read them from the file, divide them in 2 with a split function and places them in an array. the integers (the date) are suposed to go in one colomn, the first string in the next collumn, then the second string in the last column. I don't know in advance, how many rows there will be, but there will be 3 collumns.

    Is there anohter, better "thing" i can use than JTable? I just want it to look like a regular word table, no functionality, like clickinging in a cell is required.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center