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. Anyone knows the solution is highly appreciated..
I think you should do the following
Create a class for each table
to create dynamic fields implement a map which stores name of the field as key and its value as the value of the map
create one object for each row and store them, in List(or map if you want to do indexing)
Implement search functions
Update it as and when required.
Jtable is the component for UI, You can easily use it and if there is some problem in displaying the data, you are always welcome to ask.
Related
I have a table from my SQL server and I have connected to and and stored all the data in a linked list. I now want to take that data from the linked list created (everything works fine) but when I try to store it in my table named customerTable it doesn't recognize my table. (My GUI is on a different class, so is my linked list and my customer object that I use to initialize get, set methods, so I think it has something to do with that)
Can anybody help me understand how I do this?
I use this code:
DefaultTableModel model = (DefaultTableModel) customerTable.getModel();
You should implement interface TableModel, to use your existing list as the back of the table model.
See How to Use Tables of the Java Tutorials, on creating table models.
so is my linked list and my customer object that I use to initialize get, set methods
If you are storing the data in a custom Object, then you need to create a custom TableModel for that Object.
Check out Row Table Model for a step-by-step example on how to create this custom TableModel for your object.
In my database(postgreSQl) is table Person which contains name and password. It is possible to dynamically(at Spring runtime) create new table by using Hibernate? For example I want to create something like single infoTable for every Person (when Person object is created). This table should have name like Person_Id+"infoTable". Is there any way to do that?
Hibernate does offer the mode called EntityMode.MAP that is excellent for unstructured data.
In order to use EntityMode.MAP, you want to create a Map<String, Object> structure where the map keys represent the column names and the object represents the value for the associated map key column. To save such data, you'd use:
session.save( "the_name_of_my_table", theEntityMap );
While this exists, I don't believe this is ideal for your use case though.
As others have suggested, you'd be better off creating an entity that contains a foreign key back to your Person entity and merely manage the multiple rows in a single table. There are numerous database features that can help easily deal with large volumes of data without having to resort to using EntityMode.MAP.
You set hibernate.hbm2ddl.auto=update in hibernate configuration, but think twice before doing so.
I have a LinkedHashSet containing book objects. Everytime the application is opened it reads in the objects into the LinkedHashSet from a serialized file.
I was using an iterator to run through the LinkedHashSet and output the data of each objects fields into a multidimensional array to populate my JTable, but what happens is that if I click the editable Boolean column it is updating the array and not the original object?
How can I populate the JTable so that selecting the check Box changes the field of the actual object and then fire the table to update? (the table will then need to pull in the new data as that boolean field of the object sets another field.
I recommend to implement a custom table model eg. based on a List.
Here is a List based read-only table model sample I once wrote:
http://puces-samples.svn.sourceforge.net/viewvc/puces-samples/tags/sessionstate-1.0/sessionstate-suite/sessionstate-sample/src/blogspot/puce/sessionstate/sample/ParticipantTableModel.java?revision=13&view=markup
Follow the tutorial to implement a writable table model:
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data
I need to populate a table using a programmatically populated ArrayList, and my requirement is to have a filter function for that table.
However, I have not found any tutorial on this, since most tables use VOs to populate their data.
Can someone please help me with this?
You can do this very easy:
Make a bean, insert a getter and setter for your arraylist and convert your bean to a DataControl. That way you can just use it as an VO (drag & drop , ...).
Including tables with filter.
I have two radiobuttons(Say rbtn_Asia,rbtn_Europe)and one JTable. When I select rbtn_Asia, table must contains Asia's data. Similarly when I select rbtn_Europe, table must contains Europe's data. (Asia's data and Europe's data is in same database which will be updated periodically). I have implemented upto this.
My problem is like this: Consider the following case: I have selected rbtn_Asia and obviously table will contain Asia's data. Now let database has got two new tuples of Asia, how can I update the JTable dynamically without selecting the rbtn_Asia once again (because rbtn_Asia is already in selected state).
In your button handler, update your implementation of TableModel, which should then fire the appropriate event. A structure that supports clear() such as Map, shown here, is convenient. More examples may be found here.