混合java版本JTable

发布于 2024-07-10 20:37:41 字数 123 浏览 5 评论 0原文

我想使用 Java 6 中新增的 JTable 行排序器。但我还需要它在 Mac OSX 中与 Java 5 兼容。

是否可以在运行时找出 JVM 版本,并在有或没有的情况下为 JTable 使用不同的代码行排序器?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2024-07-17 20:37:42

您始终可以使用 SwingX 库中的 JXTable。 它内置了排序

You could always use JXTable from the SwingX library instead. It has sorting built in.

呆萌少年 2024-07-17 20:37:42
  1. 您可以在系统属性“java.version”中找到 JVM 版本。

  2. 将 JTable 排序器对象的源代码复制到您的项目中并使用它。 请注意,除非您拥有 Sun 的许可证,否则您不得分发此文件。 因此,这对于您只在自己或公司内部使用的东西来说是可以的。 出售或将其放在网上供下载是不行的。 IANAL

  3. 编写一个实现排序器接口的帮助器类。 在这个类中,放入以下代码:

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

当抛出 ClassNotFoundException 时,该类不可用。 如果是,请使用 sorterClass 上的 Reflection 创建一个实例并将其安装在表上。

注意:您不得在任何地方导入任何 Java 6 类! 如果这样做,加载帮助器类将会失败。 此外,您必须使用 Java 5 编译代码。

  1. You can find the JVM version in the System property "java.version".

  2. Copy the source of the JTable sorter object into your project and use that. Note that you're not allowed to distribute this unless you have a license from Sun. So this is okay for something which you only use yourself or within your company. Selling or putting it on the net for download is not okay. IANAL.

  3. Write a helper class which implements the sorter interface. In this class, put this code:

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

When this throws a ClassNotFoundException, then the class is not available. If it is, use Reflection on sorterClass to create an instance and install it on the table.

Note: You must not import any of the Java 6 classes anywhere! If you do, loading the helper class will fail. Also, you must compile the code with Java 5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文