Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


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

Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
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