Mixed version java JTable

I would like to use JTable row sorter new in Java 6. But also I need it to be compatible on Mac OSX with Java 5.

Is it possible to find out the JVM version at runtime and use different code for the JTable with and without string sorter?

0


source to share


2 answers


You can always use JXTable from SwingX . He built a sort .



+1


source


  • You can find the JVM version in the "java.version" system property.

  • Copy the source of the JTable sorter object to your project and use it. Note that you are not allowed to redistribute this unless you have a license from Sun. So it's okay for something that you only use yourself or within your company. Selling it or putting it online for download is not okay. IANAL .

  • Write a helper class that implements the sorter interface. In this class, enter this code:

    Sorterclass = Class.forName ("javax.swing.table.TableRowSorter");

The class is not available when this throws a ClassNotFoundException. If so, use Reflection on sorterClass

to instantiate and set it to the table.



Note. You don't have to import any of the Java 6 classes anywhere! If you do this, the loading of the helper class will fail. Also, you have to compile your code with Java 5.

0


source







All Articles