将JScroll Pane缩小到与JTable相同的高度 [英] Shrink JScroll Pane to same Height as JTable

查看:128
本文介绍了将JScroll Pane缩小到与JTable相同的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前将JSable嵌套在JScrollPanes中,如下所示:

I currently have JTables nested in JScrollPanes like so:

我的问题是,在创建表时,每个表中的行数是可变的。我想要做的是如果表太短,则使JScrollpane变小,但如果表太长,我想将它保持在设定的大小。

My problem is that the number of rows in each table is variable when the table is created. What I want to do is make the JScrollpane smaller if the table is too short, but I want to keep it at a set size if the table is too long.

如何我可以完成这个吗?

How can I accomplish this?

推荐答案

Dimension d = table.getPreferredSize();
scrollPane.setPreferredSize(
    new Dimension(d.width,table.getRowHeight()*rows+1));

其中表示行数数据或限制。

Where rows represents the number of rows of data, or the limit.

这篇关于将JScroll Pane缩小到与JTable相同的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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