Thread: Java and JTables

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Java and JTables

    I'm trying to declare a JTable, using the following code.

    Code:
    final int SIZE = 100;
    String DetailS[] = new String[SIZE];
    String JTableLabelS[] = new String[SIZE];
    JTable jt = new JTable(DetailS,TableLabelS);
    When I compile the code that has this, I am provided the following error.

    Code:
    homeworkJava.java:38: cannot find symbol
    symbol : constructor JTable(java.lang.String[],java.lang.String[])
    location: class javax.swing.JTable
    JTable jt = new JTable(Details,TableLabelS);
    	  ^
    Last edited by xviddivxoggmp3; 07-25-2004 at 07:07 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Have you imported the package?
    My best code is written with the delete key.

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    my imports

    Below is my imports.
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    I will post the code as soon as i resolve a win32 v.s. ext3 filesystem issue I'm having.
    Last edited by xviddivxoggmp3; 07-25-2004 at 07:18 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    The problem is that there is no constructor that takes 2 one dimensional arrays.

    look here for the available options
    http://java.sun.com/j2se/1.4.2/docs/...ng/JTable.html

    you probably want this one: JTable(Object[][] rowData, Object[] columnNames)
    *note that the rowData array is 2 dimensional

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    finally i got my code for posting.
    I tried to place a string array into another string array and it didn't work.
    I tried to place the string array into a vector and it didn't work either.
    [edit1]
    I edited this post to remove the posted code.
    The updated code is in an attachment on the next post.
    [/edit1]
    Last edited by xviddivxoggmp3; 07-25-2004 at 09:26 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    I edited the code already to fix some of the issues. The code is attached below. I have overloaded my read method to allow for double array input. now I have a bunch of java exceptions I'm not familiar with.

    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.JTable+1.getColumnName(JTable.java:469 )
    at javax.swing.JTable.addColumn(JTable.java:1932)
    at javax.swing.JTable.createDefaultColumnsFromModel(J Table.java:998)
    at javax.swing.JTable.tableChanged(JTable.java:2997)
    at javax.swing.JTable.setModel(JTable.java:2825)
    at javax.swing.JTable.<init>(JTable.java:416)
    at javax.swing.JTable.<init>(JTable.java:356)
    at javax.swing.JTable.<init>(JTable.java:468)
    at homeworkJava.<init>(homeworkJava.java:40)
    at homeworkJava.main(homeworkJava.java:209)
    Last edited by xviddivxoggmp3; 07-25-2004 at 09:28 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    i fixed it, but my read in function is not working correctly for the multideminsional array.
    see below. it doesn't read it into the array correctly. the read has extra data between the two rows. please take a lok at it.
    Code:
    public void readData(File inputFile, String[][] DataStorage)
    {
    int Count1=0,Count2=0;
     
    try
    {
    BufferedReader in = new BufferedReader(new FileReader(inputFile));
    String line;
     
    while((line = in.readLine())!=null)//this part isn't putting the data in correctly
    {
    StringTokenizer tokens = new StringTokenizer(line," ",false);
    
    while(tokens.hasMoreTokens()&&tokens!=null)
    DataStorage[Count2][Count1++]=tokens.nextToken();
    
    	 Count2++;
    }
     
    for(int x=0;x<Count2;x++)//test print
    {System.out.println("\n");
    for(int y=0;y<Count1;y++)
    System.out.println(DataStorage[x][y]);
    
    }
     
    }
    catch(FileNotFoundException e)
    {
    System.out.println("File is not accessable");
    }
    catch(IOException ioe)
    {
    System.out.println(ioe);
    }
    }
    never mind i fixed the issue by resetting my Count1 variable.
    Last edited by xviddivxoggmp3; 07-26-2004 at 08:41 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed