本文介绍了我如何调整jscrollpane的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好,所以我有这个代码:
Ok so I have this code:
//adding the panel which will hold the order table
JPanel orderPanel = new JPanel();
right.add(orderPanel);
JTable order = new JTable(orderData, orderColumnNames);
JScrollPane orderPane = new JScrollPane(order);
orderPanel.add(orderPane);
我希望能够删除此空间:
And I want to be able to remove this space :
我猜这个空间是由JScrollPane占用的,但是我找不到任何将JScrollPane调整为JTable大小的方法
I guess the space is made by the JScrollPane but i can't find any method to resize the JScrollPane to the JTable's size
推荐答案
出于此处的原因,请勿调用setPreferredSize()
.相反,请覆盖 getPreferredScrollableViewportSize()
返回所需的大小.
For the reasons adduced here, don't of invoke setPreferredSize()
. Instead, override getPreferredScrollableViewportSize()
to return the desired size.
这篇关于我如何调整jscrollpane的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!