Swing: creating a JScrollPane that displays its component centered?

前端 未结 4 1236
别那么骄傲
别那么骄傲 2021-02-08 02:52

If you create a JScrollPane that has a viewport larger than the JScrollPane\'s component, it displays that component in the upper left.

Is there any way to change this b

4条回答
  •  日久生厌
    2021-02-08 03:37

    With the suggestion from Andrew, you can't have the view smaller than the viewport (and still centered).

    The cleanest way is doing it directly from the layout manager, overriding ViewportLayout. There is an implementation in the source of:

    http://www.randelshofer.ch/multishow

    Look for the class ZoomableViewportLayout, which does the job perfectly.

提交回复
热议问题