# Class ConstrainedViewportLayout

java.lang.Object
javax.swing.ViewportLayout
uk.ac.starlink.util.gui.ConstrainedViewportLayout

All Implemented Interfaces:
  `LayoutManager, Serializable`

public class ConstrainedViewportLayout extends ViewportLayout
This is a tweaked ViewportLayout implementation to work round an issue with scrollbar positioning.

The problem arises when you have scrollbar policies VERTICAL_SCROLLBAR_AS_NEEDED and HORIZONTAL_SCROLLBAR_NEVER. When the vertical scrollbar appears, it is not accounted for in the preferred size of the scrollpane component. This can, depending on the parent layout, lead to the right hand side of the view component being obscured by the scrollbar.

You can apparently work round the problem with this class, by doing

       scrollPane.getViewport().setLayout(new ConstraintedViewportLayout());

I found this solution at stack overflow. I don't really understand why it works.

Since:
  27 Nov 2017
Author:
  Mark Taylor, https://stackoverflow.com/users/463018/meyertee
See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`ConstrainedViewportLayout()`

## Method Summary

Modifier and Type
Method
Description
`Dimension`
`preferredLayoutSize(Container parent)`

### Methods inherited from class ViewportLayout

`addLayoutComponent, layoutContainer, minimumLayoutSize, removeLayoutComponent`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ConstrainedViewportLayout

public ConstrainedViewportLayout()

## Method Details

### preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)

Specified by:
  `preferredLayoutSize` in interface `LayoutManager`
Overrides:
  `preferredLayoutSize` in class `ViewportLayout`