an array of JTables

Discussion in 'Java' started by G.Schiber, Sep 14, 2003.

  1. G.Schiber

    G.Schiber Guest

    I have an array of JTables declared as:

    JTable[] tableEntity = new JTable[maxMapEntities];

    and instantiated as:

    for (int i=0; i < maxMapEntities; i++)
    tableEntity = new JTable(tableData,tableColumns);

    My gui is a map where I place entities. Each newly placed entity
    increments an intEntityID by 1 and this is also used as the index in
    the tableEntity array (index 0 is never used nor does it have to be).

    When the user selects an entity and places it on the map(where the
    mouse is clicked), I display a dialog which contains a JScrollPane
    which contains the appropriate table. The code to do this is as
    follows:

    entityTableScroll = new JScrollPane(tableEntity[intEntityID]);
    objsDialog.setContentPane(orderContainer);
    objsDialog.getContentPane().add(entityTableScroll);

    I have debugged and the intEntityID variable is being incremented
    properly for each new entity placed on the map.

    MY PROBLEM IS that a new blank tableEntity[] should be displayed for
    each new entity but the previous tableEntity[]'s data is always
    displayed. And when I save the data, each entity always has the same
    data even though on the screen for that entity the data is different.
    Any one else had a similar problem?

    Thanks a lot,
    Greg
    G.Schiber, Sep 14, 2003
    #1
    1. Advertising

  2. "G.Schiber" <> wrote in message
    news:...
    > I have an array of JTables declared as:
    >
    > JTable[] tableEntity = new JTable[maxMapEntities];
    >
    > and instantiated as:
    >
    > for (int i=0; i < maxMapEntities; i++)
    > tableEntity = new JTable(tableData,tableColumns);


    Just for curiosity, do all your JTables use the same data model? What do
    tableData and tableColumns reference that make them into different tables?

    Cheers,
    Matt Humphrey http://www.iviz.com/

    >
    > My gui is a map where I place entities. Each newly placed entity
    > increments an intEntityID by 1 and this is also used as the index in
    > the tableEntity array (index 0 is never used nor does it have to be).
    >
    > When the user selects an entity and places it on the map(where the
    > mouse is clicked), I display a dialog which contains a JScrollPane
    > which contains the appropriate table. The code to do this is as
    > follows:
    >
    > entityTableScroll = new JScrollPane(tableEntity[intEntityID]);
    > objsDialog.setContentPane(orderContainer);
    > objsDialog.getContentPane().add(entityTableScroll);
    >
    > I have debugged and the intEntityID variable is being incremented
    > properly for each new entity placed on the map.
    >
    > MY PROBLEM IS that a new blank tableEntity[] should be displayed for
    > each new entity but the previous tableEntity[]'s data is always
    > displayed. And when I save the data, each entity always has the same
    > data even though on the screen for that entity the data is different.
    > Any one else had a similar problem?
    >
    > Thanks a lot,
    > Greg
    Matt Humphrey, Sep 14, 2003
    #2
    1. Advertising

  3. G.Schiber

    G.Schiber Guest

    Matt

    Thanks for your reponse. Yes, my array of JTables use the same data
    model defined by tableData (contains 10 rows of 8 blank columns) and
    tableColumns(contains Column heading names for the table).

    Greg

    "Matt Humphrey" <> wrote in message news:<hj59b.790$>...
    > "G.Schiber" <> wrote in message
    > news:...
    > > I have an array of JTables declared as:
    > >
    > > JTable[] tableEntity = new JTable[maxMapEntities];
    > >
    > > and instantiated as:
    > >
    > > for (int i=0; i < maxMapEntities; i++)
    > > tableEntity = new JTable(tableData,tableColumns);

    >
    > Just for curiosity, do all your JTables use the same data model? What do
    > tableData and tableColumns reference that make them into different tables?
    >
    > Cheers,
    > Matt Humphrey http://www.iviz.com/
    >
    > >
    > > My gui is a map where I place entities. Each newly placed entity
    > > increments an intEntityID by 1 and this is also used as the index in
    > > the tableEntity array (index 0 is never used nor does it have to be).
    > >
    > > When the user selects an entity and places it on the map(where the
    > > mouse is clicked), I display a dialog which contains a JScrollPane
    > > which contains the appropriate table. The code to do this is as
    > > follows:
    > >
    > > entityTableScroll = new JScrollPane(tableEntity[intEntityID]);
    > > objsDialog.setContentPane(orderContainer);
    > > objsDialog.getContentPane().add(entityTableScroll);
    > >
    > > I have debugged and the intEntityID variable is being incremented
    > > properly for each new entity placed on the map.
    > >
    > > MY PROBLEM IS that a new blank tableEntity[] should be displayed for
    > > each new entity but the previous tableEntity[]'s data is always
    > > displayed. And when I save the data, each entity always has the same
    > > data even though on the screen for that entity the data is different.
    > > Any one else had a similar problem?
    > >
    > > Thanks a lot,
    > > Greg
    G.Schiber, Sep 15, 2003
    #3
  4. "G.Schiber" <> wrote in message
    news:...
    > Matt
    >
    > Thanks for your reponse. Yes, my array of JTables use the same data
    > model defined by tableData (contains 10 rows of 8 blank columns) and
    > tableColumns(contains Column heading names for the table).


    Ok. I'm thinking that because they share the same data model as the data
    are updated by the first dialog, the data then appears in subsequent JTables
    because they're really all the same. I don't think JTables copy the data as
    an initial state, but use it as the underlying model. You may be able to
    tell by creating mutiple tableData copies during JTable creation.

    I havn't used JTables in a while, but normally views share references to
    data.

    Cheers,
    Matt Humphrey http://www.iviz.com/
    Matt Humphrey, Sep 15, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BNM

    JButtons in JTables

    BNM, Jan 30, 2004, in forum: Java
    Replies:
    0
    Views:
    465
  2. freesoft_2000

    JTables

    freesoft_2000, Feb 8, 2005, in forum: Java
    Replies:
    1
    Views:
    677
    Andrew Thompson
    Feb 9, 2005
  3. freesoft_2000

    JTables

    freesoft_2000, Jun 23, 2005, in forum: Java
    Replies:
    1
    Views:
    516
    Andrew Thompson
    Jul 4, 2005
  4. Replies:
    1
    Views:
    340
    VisionSet
    Mar 7, 2006
  5. Replies:
    4
    Views:
    505
    Chase Preuninger
    Apr 27, 2008
Loading...

Share This Page