JTable在JScrollPane中具有可调整大小的JFrame的固定大小吗? [英] JTable in JScrollPane fixed size with resizeable JFrame?

查看:50
本文介绍了JTable在JScrollPane中具有可调整大小的JFrame的固定大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JScrollPane内有一个JTable.我想让列在调整大小时保持固定.这些行保持相同的大小,并且有一个滚动条可以上下移动.我无法使滚动条在垂直方向上以相同的方式工作.

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.

这是我的项目的图片,其中Duke的y轴是完全法线,并且具有滚动条以滚动到图像的底部,水平部分明显弄乱了,并且不应该扩展得那么远.

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.

所以我的问题基本上是这样结束的;如何固定JTable的大小以免在JScrollPane中调整大小,然后如果太大,则显示滚动条.

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.

推荐答案

将表格的自动调整大小模式设置为关闭"

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

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

看看 JTable#setAutoResizeMode 了解更多详情.

Take a look at JTable#setAutoResizeMode for more details.

更新

我应该提到,这意味着您将负责确定每一列的大小.

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

看看如何使用表设置和更改列宽

这篇关于JTable在JScrollPane中具有可调整大小的JFrame的固定大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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