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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Creating Custom table in Java

  • 28-11-2011 3:56pm
    #1
    Registered Users, Registered Users 2 Posts: 846 ✭✭✭


    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: 11,989 ✭✭✭✭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: 846 ✭✭✭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