![]() ![]() Some of the additional features that MiGLayout provides are the ability to control whitespace, set component size, and use platform-specific styles. Because of this, it can be used in place of even the simplest layout managers, such as BorderLayout or FlowLayout-without adding additional coding complexity, and still provide finer control when desired. To accomplish this, it abstracts the underlying grid away from the user and handles these details internally, which allows the user to choose whichever paradigm is most appropriate for the current use-case. However, it provides constraints that allow it to be used conceptually as a flowing or docking layout it even provides absolute positioning of some components. MiGLayout is a grid-based layout underneath, as is FormLayout or GridBagLayout. ![]() For a short example using the API approach, please refer to the "API Creation of Constraints" section in Grev's Quick Start Guide. This article, and the examples provided within it, focus exclusively on this more concise method of configuration. Full functionality can be achieved with the optional String constraints passed to the MiGLayout constructor and the container add methods. However, none of these API options is necessary. There are also get and set methods provided for manipulating String constraints on the components or the layout manager at any time after the components have been added. This API provides exactly the same functionality as the String constraints but provides the advantages of compile-time error checking and Javadocs. If String constraints make you uncomfortable, there is also a builder-style API available. ![]() This makes it easy to move components around in the layout simply by changing the order of the add calls. The advantage of this approach is that it does not add any additional lines of code for layout management, and the configuration for each component is contained in one easy-to-find location. ![]() Simply construct a MiGLayout instance when instantiating your container and then pass in String constraints as you add each component. It requires no special APIs, builder classes, or container types. MiGLayout was designed to be an outwardly simple implementation of the LayoutManager interface that is configured with String constraints. The full source code of all examples in this article is available. For a detailed discussion and code examples for JGoodies FormLayout itself, please refer to the previous SETT article on that topic. It also provides a brief discussion about how MiGLayout improves upon the JGoodies FormLayout. This article introduces the MiGLayout layout manager for Swing applications and shows by example how it addresses different use-cases in comparison with the various JDK built-in layout managers. It is available from Grev in versions for both Swing and SWT development, and it is being ported by others in the open-source community to frameworks such as JavaFX. It is designed to be a highly extensible and toolkit-agnostic Java layout manager. Later we will see examples of how MiGLayout reproduces and extends the functionality of each of the built-in layout managers.įor those of you not interested in Swing for your GUI development, please note that although this article is Swing focused, MiGLayout is not. You can combine them all into one layout with one layout manager, without resorting to using nested panels to mix layout managers. With MiGLayout, you don't have to choose between docking, grid-based, flowing, or absolute styles. Although other solutions such as FormLayout seem designed as an easier version of Sun's GridBagLayout, MiGLayout seeks to provide and improve upon the best features of all the standard layout managers, including docking layouts and even absolute positioning options. MiGLayout creator Mikael Grev set out to improve upon FormLayout and the standard layout managers by creating one layout manager that was flexible enough to work for all use-cases while remaining simple to use and maintain. As the name implies, FormLayout is excellent at producing grid-based layouts for forms and tables, but loses its simplicity when trying to produce more irregular arrangements. Other third-party solutions have been created to address these issues, such as the popular JGoodies FormLayout, which was explored in the March 2005 SETT article: Intro to JGoodies Forms. The problem with these third-party layouts is that they continue to be limited in the number of use-cases that they really handle well. Sun provides several layout managers in the JDK, but they are either limited by their simplicity, or they sacrifice ease of use and maintenance for power and flexibility. Writing complex GUI layouts for Swing applications has always been a somewhat tedious and painful process. MiGLayout: The one Java layout manager that does it all
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |