Using Swing-Specific Layouts

In addition to the AWT layouts that you saw in earlier examples in this chapter, Swing comes with four layouts of its own:

  • ScrollPaneLayout— Built into the ScrollPane component.

  • ViewportLayout— Built into the Viewport component.

  • BoxLayout— Built into the Box component, but also available as an option in other components.

  • OverlayLayout— A layout manager in which every component is added on top of every previous component.

Taking Advantage of ScrollPaneLayout in JScrollPanes

You'll never need to instantiate a ScrollPaneLayout. Instead, just make a new JScrollPane. You'll get the nine areas associated with the ScrollPaneLayout automatically:

  • A JViewport, in the center— Use it for your contents.

  • Two JScrollBars— One for horizontal ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.