java的BorderLayout

來源:互聯網
上載者:User

布局管理器有四邊和中間地區的概念。當我們增加一些事物到使用BorderLayout的面板上時我們必須使用add()方法將一個字串對象作為它的第一個自變數,並且字串必須指定(正確的大寫)“North”(上),“South”(下),“west”(左),“East”(右)或者“Center”。如果我們拼字錯誤或沒有大寫,就會得到一個編譯時間的錯誤,並且程式片不會像你所期望的那樣運行。幸運的是,我們會很快發現在Java 1.1中有了更多改進。
這是一個簡單的程式例子:
 

//: BorderLayout1.java// Demonstrating the BorderLayoutimport java.awt.*;import java.applet.*;public class BorderLayout1 extends Applet {  public void init() {    int i = 0;    setLayout(new BorderLayout());    add("North", new Button("Button " + i++));    add("South", new Button("Button " + i++));    add("East", new Button("Button " + i++));    add("West", new Button("Button " + i++));    add("Center", new Button("Button " + i++));  }} ///:~

除了“Center”的每一個位置,當元素在其它空間內擴大到最大時,我們會把它壓縮到適合空間的最小尺寸。但是,“Center”擴大後只會佔據中心位置。
BorderLayout是應用程式和對話方塊的預設布局管理器。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.