Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Creating Custom table in Java

  • 28-11-2011 04:56PM
    #1
    Registered Users, Registered Users 2 Posts: 862 ✭✭✭


    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, Registered Users 2 Posts: 12,025 ✭✭✭✭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, Registered Users 2 Posts: 862 ✭✭✭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