an array of JTables

G

G.Schiber

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
 
M

Matt Humphrey

G.Schiber said:
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 (e-mail address removed) 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

G.Schiber

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 said:
G.Schiber said:
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 (e-mail address removed) 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
 
M

Matt Humphrey

G.Schiber said:
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 (e-mail address removed) http://www.iviz.com/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top