Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion, Adobe Flex

ColdFusion: Article

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.


More Stories By 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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Announcing Poland #DigitalTransformation Pavilion
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
CloudEXPO | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
In past @ThingsExpo presentations, Joseph di Paolantonio has explored how various Internet of Things (IoT) and data management and analytics (DMA) solution spaces will come together as sensor analytics ecosystems. This year, in his session at @ThingsExpo, Joseph di Paolantonio from DataArchon, added the numerous Transportation areas, from autonomous vehicles to “Uber for containers.” While IoT data in any one area of Transportation will have a huge impact in that area, combining sensor analytic...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
I think DevOps is now a rambunctious teenager - it's starting to get a mind of its own, wanting to get its own things but it still needs some adult supervision," explained Thomas Hooker, VP of marketing at CollabNet, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.