Classic Tips: Class Up Those Widgets With Form Layouts



Email    print   
July 30, 2008 —  (Page 1 of 3)
With a nice layout, applications can be not only useful, but also attractive, fun and easy to use. Fortunately, Eclipse has many layout classes to help you position widgets in a view.

The major ones include FillLayout, RowLayout, GridLayout and FormLayout. FillLayout is the simplest layout class and lays out widgets in a single row or column, forcing them to be the same size. Instances of RowLayout determine the size and position of the widgets by placing them in horizontal rows or vertical columns. RowLayout has a number of fields, including height and width, that can be specified by adding a RowData object to the widget using this layout.

Instances of GridLayout arrange widgets in a grid. Like RowLayout, GridLayout has a number of configuration fields, and the widgets it lays out can have an associated layout data object called a GridData.

The layout class I like to use the most is FormLayout. If I am not arranging widgets in a grid, that’s the layout I always choose. A FormLayout controls the position of widgets using a combination of FormData and FormAttachment objects assigned to each widget, which enables me to precisely configure the left, top, right and bottom edges of each widget that is using the layout.

Let’s start with an example. Listing 1 (less the getters and setters for the instance variables) produces the window shown in Figure 1. Notice in the createLayout(..) method that each Button is assigned an instance of FormData, e.g., getFirstButton().setLayoutData(data).

The FormData instance has fields top, bottom, left and right assigned to instances of FormAttachment. The FormAttachment constructor lets me specify a percentage and pixel offset placing the widget’s edge relative to the composite object containing the widget, which in this case is the Shell.

Based on the code below, my FirstButton has its left and top edges connect to the left and top edges of the shell (with a margin offset) and the right edge is 75 percent of the way across. You can also set the height and width of the widget providing you don’t attach a FormAttachment to the FormData bottom field. In the code below, I made my FirstButton 30 pixels in height. The SecondButton was placed using different attachments.




Pages 1 2 3 


Share this link: http://sdt.bz/32656
 
Most Read Latest News Blog Resources

Add comment


Name*
Email*  
Country     


  • Comment
Loading




close
NEXT ARTICLE
Devart Lightweight Database Drivers Beef Up the Direct Mode Functionality for Oracle and Speed Up Working with PostgreSQL!
Support for connection using Service Name in the Direct mode is added to Devart dbExpress driver for Oracle Read More...
 
 
 
 
News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 

Download Current Issue
FEBRUARY 2012 PDF ISSUE

Need Back Issues?
DOWNLOAD HERE

Want to subscribe?


 
blogs tab
Are you at risk for burnout?
Burnout is a severe problem and it can strike at any time. Here's how to tell if you are nearing the edge.
02/09/2012 02:16 PM EST

Agility, mom, and apple pie
If we're to evaluate the state-of-the-art in software development, we should start with the values espoused in the Agile Manifesto.
02/07/2012 11:57 AM EST

RIM woos developers with free tablet
How do you get more apps ported to the BlackBerry PlayBook? By giving every developer a free tablet, of course!
02/04/2012 01:57 PM EST

GitHire: Use Headhunters to Find Your Perfect Programmer
Are you a hiring manager tired of scouring the job boards? Check out this new service that will find 5 people interested in your jobs.
02/03/2012 12:17 PM EST

Facebook claims hacker cred
Facebook's SEC S-1 filing form includes a short essay on the Hacker Way by Mark Zuckerberg himself.
02/02/2012 08:26 AM EST

Ryan Dahl steps down
Ryan Dahl, creator of Node.js, steps back from his position as gatekeeper for the project.
02/01/2012 04:58 PM EST

 
Events calendar tab
2/13/2012 to 2/16/2012
Santa Clara
TechWeb

2/26/2012 to 2/29/2012
San Francisco
BZ Media

2/27/2012 to 3/2/2012
San Francisco
RSA

3/4/2012 to 3/7/2012
Las Vegas
IBM Tivoli

3/5/2012 to 3/9/2012
San Francisco
TechWeb