Java Swing: JScrollPane not working

后端 未结 2 1411
情深已故
情深已故 2021-01-14 00:55

I have a JPanel which contains some fields. The height of the JPanel is limited so I have to put a JScrollPane around it so people can scroll down.

As you can see be

相关标签:
2条回答
  • 2021-01-14 01:39

    Your DetailPanel has no layout manager associated with it, which means it doesn't expand when you add children to it, which means the JScrollPane doesn't have anywhere to scroll. Either call setLayout() on your DetailPanel or override getPreferredSize() to add up the heights of its children and return a meaningful value.

    0 讨论(0)
  • 2021-01-14 01:43

    I could be wrong, but I think this might be happening because DetailPanel's layout is null. What happens if you use a BoxLayout in vertical orientation and call detail.setPreferredSize(new Dimension(140,400));?

    0 讨论(0)
提交回复
热议问题