<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    so true

    心懷未來,開創(chuàng)未來!
    隨筆 - 160, 文章 - 0, 評(píng)論 - 40, 引用 - 0
    數(shù)據(jù)加載中……

    [轉(zhuǎn)載]Solving Common Layout Problems


    Note: This lesson covers writing layout code by hand, which can be challenging. If you are not interested in learning all the details of layout management, you might prefer to use the GroupLayout layout manager combined with a builder tool to lay out your GUI. One such builder tool is the NetBeans IDE. Otherwise, if you want to code by hand and do not want to use GroupLayout, then GridBagLayout is recommended as the next most flexible and powerful layout manager.
    Problem: How do I specify a component's exact size?
    • A handful of the more modern layout managers provide ways to override the size set by the component. Check whether the layout manager you are using allows you to specify component sizes.

       

    • Make sure that you really need to set the component's exact size. Each Swing component has a different preferred size, depending on the font it uses and the look and feel. For this reason, it often does not make sense to specify a Swing component's exact size.

       

    • If the component is not controlled by a layout manager, you can set its size by invoking the setSize or setBounds method on it. Otherwise, you need to provide size hints and then make sure you are using a layout manager that respects the size hints.

       

    • If you extend a Swing component class, you can give size hints by overriding the component's getMinimumSize, getPreferredSize, and getMaximumSize methods. What is nice about this approach is that each getXxxxSize method can get the component's default size hints by invoking super.getXxxxSize(). Then it can adjust the size, if necessary, before returning it. This is particularly handy for text components, where you might want to fix the width, but have the height determined from the content. However, sometimes problems can be encountered with GridBagLayout and text fields, wherein if the size of the container is smaller than the preferred size, the minimum size gets used, which can cause text fields to shrink quite substantially.

       

    • Another way to give size hints is to invoke the component's setMinimumSize, setPreferredSize, and setMaximumSize methods.

       

    • If you specify new size hints for a component that is already visible, you then need to invoke the revalidate method on it, to make sure that its containment hierarchy is laid out again. Then invoke the repaint method.

    Note:  No matter how you specify your component's size, be sure that your component's container uses a layout manager that respects the requested size of the component. The FlowLayout and GridBagLayout managers use the component's preferred size (the latter depending on the constraints that you set), but BorderLayout and GridLayout usually do not. The BoxLayout manager generally uses a component's preferred size (although components can be larger), and is one of the few layout managers that respects the component's maximum size.

    Problem: My component does not appear after I have added it to the container.

    • You need to invoke revalidate and repaint after adding a component before it will show up in your container.

    Problem: My custom component is being sized too small.

    • Does the component implement the getPreferredSize and getMinimumSize methods? If so, do they return the right values?
    • Are you using a layout manager that can use as much space as is available? See Tips on Choosing a Layout Manager for some tips on choosing a layout manager and specifying that it use the maximum available space for a particular component.

    posted on 2007-12-20 20:02 so true 閱讀(110) 評(píng)論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 8x成人永久免费视频| 13小箩利洗澡无码视频网站免费| 精品国产污污免费网站aⅴ| 亚洲不卡中文字幕无码| a级成人毛片免费视频高清| 国产成人亚洲综合无码精品| 在线观看免费无码专区| 亚洲成亚洲乱码一二三四区软件| 最近免费mv在线观看动漫| 久久综合九九亚洲一区| 国产精品免费观看| 亚洲综合av一区二区三区不卡| 久久久久亚洲Av无码专| 色猫咪免费人成网站在线观看| 亚洲精品电影天堂网| 黄页网站免费观看| 亚洲成a人片在线观看天堂无码| 国产女高清在线看免费观看 | 国产亚洲成归v人片在线观看| 乱爱性全过程免费视频| 国产亚洲一区二区在线观看| 免费人妻无码不卡中文字幕系| 亚洲精品在线电影| 成年性羞羞视频免费观看无限| 亚洲AV永久无码天堂影院| 免费成人午夜视频| 亚洲一区二区三区精品视频| 国产一精品一AV一免费孕妇| 国产在亚洲线视频观看| 亚洲熟女一区二区三区| 国内精品免费麻豆网站91麻豆| 亚洲精品无码久久久久久| 亚洲综合色区在线观看| 亚洲a无码综合a国产av中文| 亚洲中文字幕伊人久久无码| 久久国产精品2020免费m3u8| 亚洲中文字幕一二三四区| 亚洲美日韩Av中文字幕无码久久久妻妇 | 一二三区免费视频| 亚洲成a人片毛片在线| 亚洲?V无码成人精品区日韩|