It can also be applied to other containers as well, such as JPanel. In case you didn’t recognize it, the above line is a takeoff on a book that I used to read to my children about a little railroad engine that had trouble remembering that he had to “stay on the rails, no matter what.” I’ll bet that book was read to many of you by your parents as well.īoxLayout is the default layout manager for a Box container. Manually Resized Version of the GUI from Figure 1.Īs you can see, making the container narrower caused the components on the ends to become partially obscured due to their determination to “stay in the line, no matter what.” I will show you the code that was used to produce this screen shot later in this lesson.Īlso in the previous lesson, I explained that if the user manually resizes a container that contains components laid out according to BoxLayout, the components stay in their line formation, even if this means that some of the components are no longer visible.įigure 2 is a screen shot of the same GUI after having manually resized it to make it narrower.įigure 2. In the program used to produce the above screen shot, the alignmentY property was used to control the vertical positions of the five components relative to one another. The primary purpose of this lesson is to investigate the use of the alignmentX and alignmentY properties that many components inherit from the JComponent class. (It is also possible to place components along a vertical axis in BoxLayout.) I explained that the BoxLayout.X_AXIS constant was used when constructing the BoxLayout to cause the components to be placed along the horizontal axis. I showed you the screen shot in Figure 1, which shows five components placed in a JFrame object using the BoxLayout manager.įigure 1. I will show you how to place components on the horizontal axis, and how to establish their vertical positions relative to one another by setting the alignmentY property value.Īlso in the previous lesson, I introduced you to the Box container and the BoxLayout manager. In this lesson, I will show you how to use a Box container with its default BoxLayout manager. The lessons identified on that list will introduce you to the use of Swing while avoiding much of the detail included in this series. The Table of Contents on my site provides links to each of the lessons at. I also maintain a consolidated Table of Contents at Baldwin’s Java Programming Tutorials. You will find those lessons published at. In the previous lesson entitled Swing from A to Z, Alignment Properties and BoxLayout, Part 1, I recommended a list of my earlier Swing tutorials for you to study prior to embarking on a study of this set of lessons. That will make it easier for you to scroll back and forth among the different figures and listings while you are reading about them. You may find it useful to open another copy of this lesson in a separate browser window. This series is intended for those persons who need to understand Swing at a detailed level. This series of lessons entitled Swing from A to Z, discusses the capabilities and features of Swing in quite a lot of detail.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |