Java 可视化 - 如何在 Java 中转置 JTable? [英] Java Visualization - How to transpose a JTable in java?

查看:29
本文介绍了Java 可视化 - 如何在 Java 中转置 JTable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找允许在我的 UI 上转置 jTable 的方法.可能是通过单击按钮或其他操作.我的主要问题是我应该如何为此目的构建数据模型(abstractTableModel)?Java中是否有任何现成的方法支持这种转置?

I am looking for methods to allow transposing my jTable on my UI. It could be by clicking a button or other action. My main question is how should I build the data model(abstractTableModel) for such purpose? And is there any ready-to-use method support such transposing in Java?

推荐答案

如果您在谈论行/列反转,那么在 Swing 中它相当简单:

If you're talking about rows/column inversion, it is fairly simple in Swing:

  1. 创建表示列和行的普通表模型类.
  2. 创建倒表模型类,它是普通模型类的包装器.唯一的区别是您恢复对列和行的调用.例如,在您的包装模型的 getColumnCount 方法中,您应该调用内部模型的 getRowCount.
  3. 实例化两个模型后,只需使用 setModel 方法在 JTable 中替换它们即可.
  1. Create your normal table model class representing columns and rows.
  2. Create your inverted table model class which is a wrapper around your normal one. The only difference is that you revert calls for columns and rows. For example in getColumnCount method of your wrapper model you should call getRowCount of the internal one.
  3. Once you have your two models instantiated it is just a matter of replacing them in your JTable using setModel method.

希望有帮助..

这篇关于Java 可视化 - 如何在 Java 中转置 JTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆