Constructing SWT Layouts
StackLayout
StackLayout is different from the other layout classes. StackLayout displays only one Control at a time; however, other layout classes attempt to display many Controls at a time. StackLayout is used in property pages, wizards, and so forth.
The StackLayout has the properties listed in Table 9.
Figure 16. StackLayout Example
Figure 16 shows a simple stack layout example. We click on the Show Next Group object each time to change the top control.
Figure 17. StackLayout Example
Figure 17 shows an example of StackLayout. A stack of controls exists. It is allowed to display only one control at a time. The highlighted picture on the right shows the topControl (active) control.
Source 8. StackLayout example |
// ... shell.setLayout(new GridLayout()); final Composite parent = new Composite(shell, SWT.NONE); parent.setLayoutData(new GridData()); final StackLayout layout = new StackLayout(); parent.setLayout(layout); |
We have three groups and we add button controls to those groups. Afterwards, we need to set the
initial topControl. We create an action listener when the button is clicked. The action listener
changes the top control and calls the layout() method of the
parent control. This step is very important: If you do not call the layout method of the
parent control, you won't be able to see any change.
About the Author | |
![]() |
|
Resources
Links
- SWT Programming with Eclipse, by Koray Güclü, http://www.developer.com/java/other/article.php/3330861
- A First Look at Eclipse Plug-In Programming by Koray Güclü, http://www.developer.com/java/other/article.php/3316241.
- Understanding Layouts in SWT, by Carolyn MacLeod.
- Eclipse User Interface Guidelines, by Nick Edgar, Kevin Haaland, Jin Li, and Kimberley Peter.
- Java Tutorial - Creating a GUI with JFC/Swing.
- Eclipse uses the Common Public License.
- Eclipse download site: http://www.eclipse.org/downloads/
- Eclipse Java documentation.
- Java download Web site: http://java.sun.com/downloads/
Books
- David Gallardo, Ed Burnett, Robert McGovern (2003) Eclipse in Action: A Guide for Java Developers, Manning Publications.
- Sherry Shavor, Jim D'Anjou, Scott Fairbrother (2003) The Java Developer's Guide to Eclipse, Addison-Wesley Professional
Page 5 of 5
This article was originally published on April 15, 2004