I'm new to Java coming from .Net . Java seems to have lots of Layout Managers to choose 开发者_开发问答from. Which one can anchor like in .Net and which one can dock like in .Net?
Thanks!
I have not used .Net, but if I understand you correctly, the Docking layout manager is provided by the BorderLayout.
A BorderLayout has 4 borders (North, South, East, West) and a Center panel. A JToolBar that has been set to Floatable, can float, or can be docked to one of the 4 borders of the border layout.
From what I have just read about the anchor layout, and how it resizes as the screen resizes (i.e. the percentage of space allocated to the component), then the Swing equivalent is the GridBagLayout. It is extremely configurable and capable, but many people find it difficult to get to grips with.
JToolBar
is one such component, as shown in How to Use Tool Bars.
You can find all the layout manager well described here A Visual Guide to Layout Managers and chose the one the better fits your needs (I don't know how anchor/dock work in .Net). I find pretty useful GroupLayout together with components preferred size and SpringLayout if you need to design a complex layout (but SpringLayout is usually verbose and a bit annoying to maintain).
The most similar environment to winforms in Java is the GroupLayout(aka Matisse). It works much like the winforms designer in visual studio. It is not meant to be hand coded, but is built to be used by tools. The most popular IDE that uses the GroupLayout is Netbeans, but other implementations exist for Eclipse and possibly IntelliJ.
FreeLayout, used by the Matisse GUI builder in the NetBeans IDE: that's what you're looking for.
(You don't want to code FreeLayout by hand: that is a layout meant for code-generating WYSIWYG visual designers like Matisse.)
精彩评论