We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Jtable Keep content updated + sorted

qbawler311
qbawler311 asked
on
Medium Priority
319 Views
Last Modified: 2012-05-05
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);
}
Comment
Watch Question

Top Expert 2006
Commented:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:

Author

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?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Author

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

Author

Commented:
To compensate for the extra help I need I'm happy to up the points.  I haven't made any good GUI's...:-)

Author

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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.

Author

Commented:
OK I got it let me get back my 200 points I added and I will split up the 200 originally posted?
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Not sure if you can reduce the points (it probably says Increase only)
Top Expert 2006

Commented:
the first post provides everything you need to sort a table
posting over posts would confuse the asker ;-/

Author

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.
Top Expert 2006

Commented:
the tablesorter model would take responsibility of that as you only need to update cells
Top Expert 2006

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.