Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
User Interface Layout in Adobe Flex 2.0
Creating a user interface is just like making a floor plan

Creating a user interface is just like making a floor plan. You have your "room," which is the screen, and you have the "furniture," which is your user interface elements. This article describes many of the ways to position those elements on the screen using XML tags (which we call MXML.)

Flex applications are written with a combination of component declarations as MXML tags and ActionScript programming code. A "component" refers to any object in Flex that has a visual aspect. Buttons, Sliders, Labels, and CheckBoxes are examples of "control" components. There are other components that are very important to the layout of a Flex application. These other components are "containers" in which you put controls to position them on the screen.

There's a Layout Manager in the Flex architecture. This is the entity that is responsible for carrying out the layout instructions. Once the components are created, the Layout Manager asks every container for its size. Each container in turn asks each child for its size. This continues until the Layout Manager has a pretty good idea of how big everything is. Then it carries out the placement instructions as best it can.

Layout
The easiest way to place components is with absolute positioning and setting the x and y coordinates. The origin, (0,0), is in the upper left-hand corner. For example, to position a button so that it's 10 pixels from the left edge and 30 pixels from the top edge, type this MXML tag:

<mx:Button label="Push Me" x="10" y="30" />

Simple enough. You can use this technique to position all of your components.

That's all well and good, but now suppose you want a layout like this:

Image A

Besides position, most components have width and height properties. To start, you could create your layout like this:

<mx:Text text="My Title Goes Here" x="35" y="10" />
<mx:DataGrid x="0" y="50" width="200" height="200" />

Now comes the question: How do I make the DataGrid take up the entire width of the application space and how do I make the DataGrid use up the rest of the height? In other words, you have no idea how big the user will make their browser. It could be 200x250. Or it could be 1024x768. It would be nice if the components could automatically expand to fill the space. Actually, that's easy. Not only can you specify the width and height of a component in pixels, you can also specify it as a percentage of the container in which they are placed. This is an important fact and we'll come back to it shortly.

<mx:DataGrid x="0" y="50" width="100%" height="100%" />

Using 100% for the width and height makes the DataGrid use up the space in those directions. When I first saw this I expected that I would have to know the height of the Text control, or the percentage of space that the Text control was using. Not necessary. The Flex Layout Manager figures it out. It knows you want the top of the DataGrid to be positioned at 50 pixels. Having a height of 100% means it takes up the rest of the vertical space. When you run this Flex application you can resize the browser and the DataGrid will adjust its size.

Image B

But what about that title Text? Suppose you'd like it to be centered above the DataGrid and move left and right as the browser window's width changes. That's easy too.

Flex has another way to position components called constraints and it's probably the method you'll use the most. Constraints let certain container components (those that allow absolute positioning) shift their content according to the parameters you specify. Using constraints is a lot better than using x, y, width, and height, because it positions the components dynamically and lets them adapt to the size of the browser window.

Let's start with the DataGrid. So far the DataGrid is at the edge of the browser space. Using constraints can give it some margins to make it look nicer:

<mx:DataGrid left="10" top="50" right="10" bottom="10" />

The constraints in this MXML tag are named left, top, right, and bottom. Each constraint gives the position, in pixels, from that edge of the container component. The tag above says DataGrid should always be 10 pixels from the left edge, 50 pixels from the top edge, 10 pixels from the right edge, and 10 pixels from the bottom edge.

Centering components uses another constraint:

<mx:Text text="My Title Goes Here" horizontalCenter="0" />

Image C

The horizontalCenter constraint is the number of pixels that the center of the component should be from the center of the container. That is, when set to 0, the center of the Text component is exactly at the center of the application. If you set horizontalCenter="-20" then the center of the Text component would be shifted left of center by 20 pixels. A positive number shifts the center of the component to the right. There's a corresponding verticalCenter constraint too.

Note: You don't have to use all the constraints with every control. Use only the ones that make sense. For example, to make a component hug the right edge, use right="0" but don't use left. If you do use both left and right the component will be stretched across the application.

Flex Builder
If you have Flex Builder 2 you can use the Design View function to easily position components.

Image D

The layout tool (lower right) allows you to give exact values for size, position, and constraint.


About Peter Ent
Peter Ent is a Web application developer specializing in Rich Internet Applications. He has more than 20 years of experience ranging from keypunches to wireless PCs.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
As a result, it said, of “customer feedback and evolving usage patterns,” Microsoft cut the price of its cloud-ified SQL Azure database 48%–75% for databases larger than 1GB and introduced a new entry-level 100MB model. It blogged that it’s noticed that many projects start smal...
Wide and cheap availability of cloud-based media services is upon us. With the transformations these services are already bringing to the consumption of music, video and interactive media, change has likewise come to professional workflows. Documents in 2012 are read, written, co...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical ...
Fresh off a happy quarter, Rackspace said Thursday that it’s bought SharePoint911, one of those you-never-heard-of-them outfits that does SharePoint consulting, training and JumpStart services so it can deliver newfangled SharePoint services along with its existing SharePoint hos...
Cloud is a shift from the focus on underlying technology implementation to leveraging existing implementations and further building upon them. Cloud orchestration or a network of clouds is the wave of the future where these clouds can operate with elasticity, scalability, and eff...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News

Mayor Jerry Sanders and San Diego City Councilmen Kevin Faulconer and Todd Gloria o...