问题
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:
- Create your normal table model class representing columns and rows.
- 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 callgetRowCount
of the internal one. - Once you have your two models instantiated it is just a matter of replacing them in your
JTable
usingsetModel
method.
Hope that helps..
来源:https://stackoverflow.com/questions/17667550/java-visualization-how-to-transpose-a-jtable-in-java