Results 1 to 10 of 10
Thread: JTable Sorting
- 03-20-2012, 05:06 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
JTable Sorting
Hello, I am making a program for class, and it is a Swing GUI based program and you input a few different things and it puts it into a JTable. One value it puts in the table is a ratio that is calculated from two numbers the user inputs. I need to be able to sort the table by descending ratio values.
Any help would be appreciated,
Thanks
JMenu
Website won't let me attach the .zip of the java file, so here's a link to it PeelPetHouse.javaJava Code:// Display All Animals Menu Method public void displayall () { contentPane = getContentPane (); if (infoPane != null) contentPane.remove (infoPane); infoPane = new JPanel (); infoPane.setLayout (new BorderLayout ()); L1 = new JLabel ("Peel Pet House Animals:", JLabel.CENTER); L1.setFont (new Font ("Arial", Font.BOLD, 24)); infoPane.add (L1, BorderLayout.NORTH); L2 = new JLabel ("End of Page", JLabel.CENTER); infoPane.add (L2, BorderLayout.SOUTH); String [] columnNames = {"Breed", "Category", "Acquisition Price", "Selling Price", "Profit Ratio"}; table = new JTable (animalData, columnNames); JScrollPane scrollPane = new JScrollPane(table); infoPane.add (scrollPane, BorderLayout.CENTER); contentPane.add (infoPane); validate (); }
- 03-20-2012, 05:38 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Re: JTable Sorting
Have you tried a TableRowSorter object?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-20-2012, 06:37 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Re: JTable Sorting
I am fairly new to swing, and java actually, and Im not too sure on how to input TableRowSorter into my program. I was also thinking that instead of sorting the table by the value, it will determine the highest to lowest integers and then place them in the table accordingly.
Alternatively show where I would implement the TableRowSorter in my code.
Thanks,
RivalLast edited by rival; 03-20-2012 at 06:45 PM.
- 03-20-2012, 06:58 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Re: JTable Sorting
You haven't read the API documentation for that class because it has a few simple examples how to add it to your JTable ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-20-2012, 07:03 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Re: JTable Sorting
Might I also add Im using a course required Ready to Program 1.7.1 that is only using Java 1.4.2
- 03-20-2012, 08:50 PM #6
Re: JTable Sorting
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-20-2012, 08:55 PM #7
Re: JTable Sorting
Even if that course happens to be free, it's not worth the money you paid for it. You could go through the Oracle Java tutorials instead -- they are free.
Would you want to learn driving in a car you have to hand-crank to start, with a manual choke and timing advancer that you have to keep adjusting according to speed and gradient?
From Java 2 Platform, Standard Edition (J2SE) 1.4.2
dbJ2SE 1.4.2 is in its Java Technology End of Life (EOL) transition period. The EOL transition period began Dec, 11 2006 and will complete October 30th, 2008, when J2SE 1.4.2 will have reached its End of Service Life (EOSL)Why do they call it rush hour when nothing moves? - Robin Williams
- 03-20-2012, 10:32 PM #8
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Re: JTable Sorting
No it's a school course, which I need to graduate haha sorry for the misunderstanding.
- 03-21-2012, 12:04 AM #9
Re: JTable Sorting
A course in software history?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-21-2012, 04:25 AM #10
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Sorting in JTable
By jobi in forum SWT / JFaceReplies: 4Last Post: 10-04-2011, 10:24 AM -
Problem with sorting columns using Jtable
By aspiring_programmer in forum AWT / SwingReplies: 0Last Post: 12-02-2010, 02:43 PM -
JTable sorting
By mtyoung in forum Advanced JavaReplies: 6Last Post: 11-10-2009, 05:59 AM -
Sorting JTable
By mm2236 in forum AWT / SwingReplies: 0Last Post: 04-09-2009, 04:37 PM -
sorting JTable
By mansi_3001 in forum Advanced JavaReplies: 3Last Post: 08-10-2007, 06:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks