Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

You Don't Have to Swing to Make Great Java UIs

The Standard Widget Toolkit (SWT) provides five different layout managers to help you create complex, flexible user interfaces for your Java apps. Find out about all five of them in this article.


advertisement
thorough understanding of Layout Managers is essential to building complex user interfaces in Java applications. The Standard Widget Toolkit (SWT) provides five different layout managers. This article uses simple examples to introduce all of them (see Figure 1). It also provides a detailed example for GridLayout, a very useful, flexible manager that builds screens for frequent resizing.

FillLayout
This layout is very similar to the Swing's GridLayout. It does not honor the width and height of the components placed in it—the child widgets get the entire available space. When you add multiple components, each component gets the same height and width. Unlike GridLayout, FillLayout provides two parameters, HORIZONTAL and VERTICAL, which specify how the components will be placed.

Figure 1. The Layout Managers: This shows the SWT layout managers class hierarchy.



RowLayout
RowLayout is analogous to Swing's FlowLayout. This layout does honor the width and height of its child components. Unlike FlowLayout, where the child components are placed from left to right, RowLayout allows you to position components from top to bottom as well. Use the following additional properties to fine tune the position of the child components within the layout:

marginLeft, marginTop, marginRight, marginBottom

Use the Pack property to set the components with equal width. Use the Justify to position the widgets across the available space within the composite.

When the number of components you've added to RowLayout exceeds available width, RowLayout wraps the components into the next row (like FlowLayout). Set each components' width and height using the width and height properties.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap