advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement



Title: Professional Java Programming
ISBN: 186100382x
US Price: $ 59.99
Canadian Price:
C$ 89.95
UK Price: £ 45.99
© Wrox Press Limited, US and UK.

Reviews : Java Books :
Professional Java Programming : Using Layout Managers

Let's assume that a container has been created that uses a GridBagLayout to manage the size and position of its child components, and that a width of 400 pixels is needed to display the components using their minimum sizes. However, let's also assume that when the layout manager prepares to arrange the components, it determines that the container is 600 pixels wide. In this case, the GridBagLayout must determine how to distribute the extra 200 pixels to its columns.

Calculating Column Weights

The first step that the GridBagLayout must take is to calculate a weight for each column, and that weight will determine how much of the extra 200 pixels will be distributed to the column. In the simplest case where each component has a gridwidth value of 1 (in other words, no component spans multiple columns), the weight of a column is defined as the largest weightx value of any component within that column. For example, suppose that the following table represents the weightx values of components in a container:

Since the weight of a column is defined as the maximum weightx value in that column, the weights of the three columns in this grid are 50, 50, and 25, respectively. As we'll see shortly, neither the weights' absolute values nor their sum is particularly important, but you may find it easier to work with round numbers.

In the case where a component spans multiple columns, the calculation of a column's weight value is slightly more complex. Using a different set of components in some other container, let's suppose that there are three rows of components in the grid, and that the second row contains a component that spans the second and third columns as shown below. It's easy to guess the weight of the first column, since it's simply the maximum weightx value found in that column (1.0). However, it's probably not as obvious how the weight values of the remaining two columns are calculated:

To understand how the weight values were derived for the second and third columns, it's important to know that when GridBagLayout calculates column weights, it processes components in order based on their gridwidth values. In other words, GridBagLayout first examines the weightx values of all components that have a gridwidth value of 1, then those that have a value of 2, and so on. In this case, the layout manager's first iteration will process 7 of the 8 components in the container, initially ignoring the component on the second row that has a gridwidth of 2. In the process of doing so, it calculates a preliminary column weight of 0.25 for the second column and 0.5 for the third column.

On the GridBagLayout's next iteration, it processes the weightx of the component that spans the second and third columns, and must distribute that value (3.0) across the two columns. It does this by distributing the amount proportionally based upon the preliminary weight values of the columns. Specifically, it adds together the preliminary column weight values and divides the weight value of each column by that sum to determine a percentage of the spanning component's weightx value that should be distributed to the column.

For example, in this case, the preliminary weight values of the second and third columns are 0.25 and 0.5, respectively, and the sum of these two values is 0.75. Dividing the preliminary weight of the second column by 0.75 produces a value of 0.33, and dividing the third column's preliminary weight by the same 0.75 produces a value of 0.67. These values represent the percentage of the spanning component's weightx value that will be distributed to each column. Specifically, one-third (33%) will be assigned to the second column, and the remaining two-thirds (67%) will be assigned to the third column. Since the weight of the component that spans the two columns is 3, it represents a weight of 1 (3.0 * 0.33 = 1.0) for the second column and 2 (3.0 * 0.67 = 2.0) for the third.

Since the component in the second row represents a weightx value of 1 for the second column and 2 for the third column, the second column's final weight value is 1 and the third column's final weight is 2.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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