Shrink JScroll Pane to same Height as JTable

后端 未结 5 1512
独厮守ぢ
独厮守ぢ 2020-12-16 12:07

I currently have JTables nested in JScrollPanes like so:

\"enter

My problem is

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 12:58

    Use a GridBagLayout manager and set the maximum size of the JScrollPane to whatever you want to. If the table is larger the JScroll won't grow beyond that size.

    Then, add a glue component ( I think it is something like BoxLayout.createVerticalGlue or something like that ) which is an empty component that just takes the remaining space.

    So, when the table is smaller, this component will take the remaining space, if the table is larger, it won't take anything since the JScrollPane is using it.

提交回复
热议问题