Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Creating Custom table in Java

Options
  • 28-11-2011 4:56pm
    #1
    Registered Users Posts: 839 ✭✭✭


    Hi,
    I'm doing some Java for a project. It involves applet/servlet communication. My applet sends out a command to a servlet, and receives back a load of information using this....
    DataInputStream result = new DataInputStream(new BufferedInputStream(in));

    I do a while loop to receive all the strings.

    My question is - how do I create a custom table using this information?
    I've can see from google searches how to create an array and then build a table, something like this.....

    String columnNames[] = { "Column 1", "Column 2", "Column 3" };
    String dataValues[][] = {{ "12", "234", "67" },{ "-123", "43", "853"}};
    table = new JTable( dataValues, columnNames );

    But in this case, the data is hardcoded, and the table is created when you run the applet. But the idea for my applet is that you start with an empty table - then you click on a search button and the table is populated. Depending on the results the table could have 2 rows or 20 rows.
    I need to be able to read in my data, which is in groups like dataValues above, as I'm reading in rows from a table - then I'm guessing create an array with this data, and then update the table.
    Any guidance on how this can be done?!!

    thanks in advance

    Kelbal


Comments

  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    A JTable uses a TableModel, which can be updated independently. The JTable is bound to this TableModel, so when you update the TableModel, you can call TableModel.fireTableDataChanged()


  • Registered Users Posts: 839 ✭✭✭kelbal


    thanks Giblet. Will check this out. Having another problem that
    supersedes this one, just posted new thread about it. When I get that one sorted I can look at this.
    thanks for the help


Advertisement