gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




Vote for the Developer.com Product of the Year Winners!




Developer Jobs

Be a Commerce Partner














 


Developer News -
Security Breach Can't Halt Fedora 10's Debut    November 25, 2008
Red Hat Fedora Claims It's the Leader in Linux    November 21, 2008
Dos and Don'ts of SOA Data Access    November 20, 2008
Mandrake Linux Founder Back, Virtually    November 20, 2008
Free Tech Newsletter -

Constructing SWT Layouts
By Koray Guclu

Go to page: Prev  1  2  3  4  5  

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);
  
final Group[] group = new Group[3];
  for (int k = 0; k < group.length; k++) 
  {
    group[k] = new Group(parent, SWT.NONE);
    group[k].setText("Group " + (k + 1));

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    group[k].setLayout(gridLayout);
    
    Character character = new Character((char) ('A' + k));
    for (int i = 10; i < 20; i++)
    {
      Button bArray = new Button(group[k], SWT.PUSH);
      bArray.setText(character + "." + i);
    }
  }
layout.topControl = group[0];
  
  Button b = new Button(shell, SWT.PUSH);
  b.setText("Show Next Group");
  final int[] index = new int[1];
  b.addListener(SWT.Selection, new Listener() 
  {
    public void handleEvent(Event e) 
    {
      index[0]          = (index[0] + 1) % 3;
   layout.topControl = group[index[0]];
   parent.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


Koray Güclü

He is working as a freelance author and software architect. He is currently finishing his book on Software Architectures and Design Patterns. His main interest areas are Software Architectures, Data Warehouses, and Database Modeling.

www.korayguclu.de

Resources

Links

Books

Go to page: Prev  1  2  3  4  5  

Previous article: SWT Programming with Eclipse


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Other Java Archives






internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers