Java Visualization - How to transpose a JTable in java?

五迷三道 提交于 2019-12-11 12:51:52

问题


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?


回答1:


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..



来源:https://stackoverflow.com/questions/17667550/java-visualization-how-to-transpose-a-jtable-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!