• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic Table Creation in Java with No back end Database

 
Kal Maz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my java application I want to create a table whose data field will be updated dynamically. The table is not linked with any database. The tables' data fields are ArrayList or List type data so I want to update the fields when they are changing . I was looking into the jtable but was unable to find the way to do that. I like to see in memory if it possible. I was looking into swings also. In short, the idea is to display the tables as a pop Up window and to have as low as burden to the memory.Any one knows the solution is highly appreciated..
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15715
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Can you be more specific about your question? To store the data, can't you just create a class that holds the appropriate data structure(s), that you hold in memory?

A JTable is a Swing GUI component to display a table. Is your question about how to create a Swing GUI with a table?
 
Kal Maz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok . To be specific: I have Arraylist/list data types and I want to display those values in the table cells. So I might be using the Jtable/swings for display. When the values are changing then the associated field must change. I want to use one class for one dynamic table. e.g.

table:

A B c
3 5 8
NB: 3,5 and 8 are the AraayList/List type values now if 8 changes to 6 then it should update itself automatically. It cloud be an applet also to display that table (I am flexible about displaying idea).
I hope now it is clear.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one way might be:
originally, from the arraylist/whatever, create a TableModel
set the table's model to that TableModel.

when the arraylist/whatever changes, create a new TableModel,
setting the table's model to the newly created TableModel
 
Kal Maz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Actually I tried to create one sample class to do what Micheal Dunn advised..

First I created a class:


Then I create table model like this:



The final Class which one extends Jtable is:

But output is
1. datalist.size is 0

2.The table is empty without the row values

I know the reason is fairly understood but would be great if you let me know what is the problem(s) in the code and how to feed the data so that the first row and will be having the data from the Test1 class

Bonus Question: How to dynamically update the data field later ?

Thanks for the reply..
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are creating the MyTableModel instance, you are using the default constructor. If you look into the constructor of that class, you can see that the dataList has 0 rows and hence it shows zero. Just pass a list with the data when creating the MyTableModel.
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly recommend that you extend DefaultTableModel and not AbstractTableModel. Or you could simply use a DefaultTableModel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!