JTable in JScrollPane fixed size with resizeable JFrame?

六月ゝ 毕业季﹏ 提交于 2019-12-02 17:15:01

问题


I have a JTable inside of a JScrollPane. I want to get the columns to stay fixed when I resize it. The rows stay the same size, and there is a scrollbar to move up and down. I can't get the scrollbar to work the same way on the vertical though.

Here is a picture of my project, where the y axis of Duke is perfectly normal, and has a scrollbar to scroll to the bottom of the image, the horizontal part is clearly messed up, and should not have expanded that far.

Also, if the frame was made smaller horizontally, there should be a scrollbar just like the vertical.

So my question basically ends up like this; How do you fix the size of a JTable to not resize within the JScrollPane, and then if it's too large for it, display scroll bars.

Btw, Each cell has an image, making up the big image.


回答1:


Set the table's auto resize mode to "off"

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

Take a look at JTable#setAutoResizeMode for more details.

Update

I should mention, this will mean you will become responsible for determine the size of each column.

Take a look at How to use tables and Setting and Changing Column Widths



来源:https://stackoverflow.com/questions/14700921/jtable-in-jscrollpane-fixed-size-with-resizeable-jframe

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