the jfc also introduces the scrollpanelayout and viewportlayout managers, but they are so tightly coupled to their respective jscrollpane and jviewport components that they are virtually useless in other contexts.
youll notice a few things about these: each has a simple purpose, described in a single sentence and easy to understand. none of them use exact positioning so they avoid tight coupling to a given display area. each method has a natural organization behind it, often reflected in a real-life approach. all layout managers have the layout suffix as part of their name.
table 2 covers the implementation of new layout managers. well elaborate on their internal function after a quick look at the layout manager interfaces.
the layoutmanager interface 【推荐阅读:谈谈java的学习方向(转载)】
this article tries to take the mystery out of the black art of developing layout managers. much of the coverage in books and magazines typically centers on trying to wrench the complicated gridbaglayout into submission or demonstrates the development of a layout manager with virtually no practical use. in the real world of software engineering, the need for applicable solutions takes precedence. this article will add a trio of reusable classes to your inventory and, hopefully, a few techniques to your personal bag of tricks.
practical layout design
the basic design of a layoutmanager is fairly simple. you need to declare your class as implementing the layoutmanager interface and then implement the following methods: addlayoutcomponent(string, component) removelayoutcomponent(component) layoutcontainer(container) dimension minimumlayoutsize(container) dimension preferredlayoutsize(container) the addlayoutcomponent method is called when you use the add method in your container. typically, the add method has only one parameter, so the addlayoutcomponent method is called with the string set to null. with the borderlayout, the label indicating position is passed using the add method with the s... 下一页