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?

有帮助吗?

解决方案

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

  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.

Hope that helps..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top