Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4626994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:30:09+00:00 2026-05-22T03:30:09+00:00

I’m using Glazed Lists to sort and filter a JXTable. How can I sort

  • 0

I’m using Glazed Lists to sort and filter a JXTable.

How can I sort on out-of-table values? That is, I would like to be able to format column values in my own way, yet sort on raw values.

My current relevant code:

EventList<Foo> foos = GlazedLists.threadSafeList(new BasicEventList<Foo>());
foos.add(new Foo("bar", 5000000));

ObservableElementList.Connector<Foo> fooConnector = GlazedLists.beanConnector(Foo.class);
EventList<Foo> observedFoos = new ObservableElementList<Foo>(foos, fooConnector);

SortedList<Foo> sortedFoos = new SortedList<Foo>(observedFoos, null);

EventTableModel tableModel = new EventTableModel(sortedFoos, someTableFormat);
JXTable t = new JXTable(tableModel);

new TableComparatorChooser<Foo>(t, sortedFoos, false);

In this example, I would like to format the value in the second column as 5.0M rather than 5000000, but if I use this value in the list, it won’t sort properly.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:30:09+00:00Added an answer on May 22, 2026 at 3:30 am

    Maybe you have to disable the JXTable Sorting, so it does not interfere with the GL sorting? Something like:

    jxtable.setSortable(false);
    jxtable.setAutoCreateRowSorter(false);
    jxtable.setRowSorter(null);
    

    … and then install GlazedLists TableComparatorChooser on the table like:

    TableComparatorChooser.install(jxtable, sortedFoos, TableComparatorChooser.SINGLE_COLUMN);
    

    Or do you mean, you want to format 5000000 as 5.0M in the table, not in the List? Then you would only have to implement your TableFormat’s

    public Object getColumnValue(E yourObject, int column)
    

    to return the 5.0M representation of 5000000.

    … could well be, that I did not fully understand the problem and these answers are not helping 😉

    EDIT: Runnable example…

    Look at the code in the main method – especially the code with the START-END comment.
    I made my own very simple example, but you should understand, what I mean.

    Oh… sorry for the naming of classes/variables/… 😉

    import ca.odell.glazedlists.BasicEventList;
    import ca.odell.glazedlists.EventList;
    import ca.odell.glazedlists.SortedList;
    import ca.odell.glazedlists.gui.TableFormat;
    import ca.odell.glazedlists.swing.EventTableModel;
    import ca.odell.glazedlists.swing.TableComparatorChooser;
    import java.util.Comparator;
    import java.util.List;
    import javax.swing.ComboBoxEditor;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import org.jdesktop.swingx.JXTable;
    
    public class Tester {
    
        private static class MyObject implements Comparable<MyObject> {
    
            private final int number;
            private final String value;
    
            public MyObject(int number, String value) {
                this.number = number;
                this.value = value;
            }
    
            public int getNumber() {
                return number;
            }
    
            public String getValue() {
                return value;
            }
    
            @Override
            public int compareTo(MyObject t) {
                return value.compareTo(t.getValue());
            }
        }
    
        private static class MyTableFormat implements TableFormat<MyObject> {
    
            @Override
            public int getColumnCount() {
                return 2;
            }
    
            @Override
            public String getColumnName(int i) {
                switch (i) {
                    case 0:
                        return "FormattedNumber";
                    case 1:
                        return "String";
                    default:
                        throw new IllegalStateException();
                }
            }
    
            @Override
            public Object getColumnValue(MyObject e, int i) {
                switch (i) {
                    case 0:
                        return getNumberString(e.getNumber());
                    case 1:
                        return e.getValue();
                    default:
                        throw new IllegalStateException();
                }
            }
    
            private Object getNumberString(int number) {
                switch (number) {
                    case 1:
                        return "One";
                    case 2:
                        return "Two";
                    case 3:
                        return "Three";
                    default:
                        throw new IllegalStateException();
                }
            }
        }
    
        private static class MyComparator implements Comparator<MyObject> {
    
            @Override
            public int compare(MyObject t, MyObject t1) {
                return Integer.valueOf(t.getNumber()).compareTo(Integer.valueOf(t1.getNumber()));
            }
    
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            EventList<MyObject> list = new BasicEventList<MyObject>();
            list.add(new MyObject(1, "A"));
            list.add(new MyObject(2, "B"));
            list.add(new MyObject(3, "C"));
    
            SortedList<MyObject> sortedList = new SortedList<MyObject>(list);
    
            EventTableModel<MyObject> tableModel = new EventTableModel<MyObject>(sortedList, new MyTableFormat());
            JXTable jxtable = new JXTable(tableModel);
    
            /** 
             * START
             * - Deactivate JXTables build-in sorting
             * - Install GlazedLists sorting
             * - Set the comparator for the "string number" column
             */
    
            // deactivate sorting of JXTable
            jxtable.setSortable(false);
            jxtable.setAutoCreateRowSorter(false);
            jxtable.setRowSorter(null);
    
            // enable GlazedLists sorting
            TableComparatorChooser<MyObject> tcc = TableComparatorChooser.install(jxtable, sortedList, TableComparatorChooser.SINGLE_COLUMN);
    
            // set the comparator for your "string number" column
            List<Comparator> comparators = tcc.getComparatorsForColumn(0);
            comparators.clear();
            comparators.add(new MyComparator());
    
            /**
             * END
             */
    
            JFrame f = new JFrame("Tester");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(jxtable));
            f.pack();
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.