![]() ![]() You will also notice that each component takes up all the available horizontal space but not (as you can see with button 5) all the available vertical space. This resizing behavior is based on weights the program assigns to individual components in the GridBagLayout. The new horizontal space is split evenly among all the columns. ![]() If you enlarge the window as shown in the following figure, you will notice that the bottom row, which contains Button 5, gets all the new vertical space. The button in the second row spans all the columns the button in the third row spans the two right columns. As you can see, the grid has three rows and three columns. The following figure shows the grid for the preceding applet. Essentially, GridBagLayout places components in rectangles (cells) in a grid, and then uses the components' preferred sizes to determine how big the cells should be. Similarly, not all columns necessarily have the same width. Not all rows necessarily have the same height. A GridBagLayout places components in a grid of rows and columns, allowing specified components to span multiple rows or columns. GridBagLayout is one of the most flexible and complex layout managers the Java platform provides. Alternatively, to compile and run the example yourself, consult the example index. Java™ Web Start ( download JDK 7 or later). Here is a picture of an example that usesĬlick the Launch button to run GridBagLayoutDemo using If you are interested in using JavaFX to create your GUI, see Otherwise, if you want to code by hand and do not want to use GroupLayout, then GridBagLayout is recommended as the next most flexible and powerful layout manager. If you are not interested in learning all the details of layout management, you might prefer to use the GroupLayout layout manager combined with a builder tool to lay out your GUI. Note: This lesson covers writing layout code by hand, which can be challenging. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |