请问大虾们什么是gridbaglayout什么是xylayout啊,请赐教
那几种layout是怎么区别的啊

解决方案 »

  1.   

    GridBagLayout是网格包装布局,它可以将一个Panel按照一个方向分割成任意多块,每个分割块之间的大小是根据其与其他分割块的比例来控制的我感觉,Java的布局是Java的一个弱项,各种布局都有他的弱点。我感觉常用的布局有FlowLayout,GridLayout,GridBagLayout,CardLayout,BorderLayout另外前不久因为工作才开始使用的SpringLayout也是非常好用,尤其是在复杂页面上,他有着极大的优势,它可以把一个Panel分割成M*N的格子,然后将每一块填满即可,但是要注意的是必须所有的格子都填满,即使在画面上什么都没有,也要填上个空的Panel或者Box.createRigidArea(new Dimension(width, height));我知道就这些,楼下补充
      

  2.   

    XYLayout是Borland公司提供的。
    Sun的,你可以查看LayoutManager接口下的实现类,有所有的布局。
      

  3.   

    About XYLayout:If one of the nested panels in your UI has XYLayout, then that panel's preferredSize is determined by the layout's setWidth() and setHeight() calls, and that is the value used for the panel in computing the preferredSize of the next outer container. For example, in the default Application wizard application, the nested panel occupying the center of the frame's BorderLayout is itself initially in XYLayout and is set to size 400 x 300. This has a significant effect on the overall size of the frame when it is packed, because the nested panel report its preferredSize to be 400x300. The overall frame will be that plus the sizes necessary to satisfy the other components around it in the BorderLayout of the frame.
      

  4.   

    GridLayout:GridLayout places components in a grid of cells that are in rows and columns. GridLayout expands each component to fill the available space within its cell. Each cell is exactly the same size and the grid is uniform. When you resize a GridLayout container, GridLayout changes the cell size so the cells are as large as possible, given the space available to the container. GridLayout example  Use GridLayout if you are designing a container where you want the components to be of equal size, for example, a number pad or a toolbar.
      

  5.   

    gridbaglayout是布局中最好的一种布局,当然,书写也比较麻烦,因为有很多参数,而xylayout就比较随意一些,但效果不如gridbaglayout,至于其他的,楼住可以编个小程序看看效果
      

  6.   

    实际根据几种Layout写几个程序来看看最直观。然后通过程序中改变下属性,看看效果上的变化,对几种Layout的理解很有帮助。