Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Jtable Keep content updated + sorted

I have an array of beans, the beans contain about 8 fields each

I want each bean to represent a row of the jtable, 8 columns = 1 for each field.
I want the software to create the array of beans, post them to the Jtable, create the array of beans again (this time with updated information) then post the updated beans to the Jtable.  I also want to be able to sort the Jtable that is constatly being updated by any column.

{
TableModel jTable1Model = new DefaultTableModel(
new String[][] { { "One", "Two" },
      { "Three", "Four" },
      { "Three", "Four" } },
new String[] { "Column 1", "Column 2", "Column 3" });
      jTable1 = new JTable();
      this.getContentPane().add(jTable1, BorderLayout.CENTER);
      jTable1.setModel(jTable1Model);
}
0
qbawler311
Asked:
qbawler311
  • 6
  • 4
  • 4
  • +1
3 Solutions
 
objectsCommented:
To use your bean array in a table you'll need to extend AbstractTable model and have getValueAt() return the appropriate porperty for each column

Heres an example of a sortable table

http://www.objects.com.au:8088/objects/java/examples/swing/SortableTable.do
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
qbawler311Author Commented:
>> http://www.objects.com.au:8088/objects/java/examples/swing/SortableTable.do

Firewall refuses connection to this link.  Could you paste the code in here?
0
 
qbawler311Author Commented:
>> http://www.javareference.com/jrexamples/viewexample.jsp?id=17

If you guys could show me how to add the code to make the table at the above link sortable that is exactly what i am looking for.  Having trouble combining the information I am reading from the "AbstractTableModel" example and the "TableSorter" examples.  thank you
0
 
qbawler311Author Commented:
To compensate for the extra help I need I'm happy to up the points.  I haven't made any good GUI's...:-)
0
 
qbawler311Author Commented:
>>try:
>>
>>http://www.objects.com.au/java/examples/swing/SortableTable.do

this link worked, but the links on the page didn't...I will try at home later.
0
 
objectsCommented:
thanks for pointing that out. The ISP has just upgrade the server and it looks like it broke some links.
While I get them fixed you can manually fix the url by removing the :8088/objects
sorry for the inconvenience.
0
 
qbawler311Author Commented:
OK I got it let me get back my 200 points I added and I will split up the 200 originally posted?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Not sure if you can reduce the points (it probably says Increase only)
0
 
hoomanvCommented:
the first post provides everything you need to sort a table
posting over posts would confuse the asker ;-/
0
 
qbawler311Author Commented:
The other half of the question is how do I keep the Array of objects that I am displaying in the sorted Jtable refreshed and sorted as they are updated?...without hitting any buttens.
0
 
hoomanvCommented:
the tablesorter model would take responsibility of that as you only need to update cells
0
 
hoomanvCommented:
compile and run the example, try to alter the cells, and you'll find out how it works
in short
you only need to wrap your own TableModel into TableSorter model
then pass it to yourtable's setModel method
nothing more
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now