Java學習筆記之用Box布局swing介面

來源:互聯網
上載者:User

主要就用到了這四個方法

createHorizontalBox()

          建立一個從左至右顯示其組件的 Box

createHorizontalStrut(int width)              //左右組件之間的中間間隔就可以用這個方法來控制
          建立一個不可見的、固定寬度的組件。

createVerticalBox()

          建立一個從上到下顯示其組件的 Box

createVerticalStrut(int height)            //上下組件之間的中間間隔就可以用這個方法來控制
          建立一個不可見的、固定高度的組件。

如下

package com.geogro.webapp.applet.track;import java.awt.*;import javax.swing.*;import javax.swing.border.*;/**3G版本的資料過濾面板,輸入過濾值查詢3G值. * * @author snail * @date 07-03-26 * @version 1.0 */public class Fliter3GPanel extends JPanel {   private static Font defaultFont = new Font("SimSun", Font.PLAIN, 12); //預設字型   TitledBorder titledBorder1 = new TitledBorder("參數設定");   JTextField xTextField;   JTextField yTextField;   JTextField zTextField;   JTextField inteTextField;   DateChooserJButton fliterStartTimeButton;   DateChooserJButton fliterEndTimeButton;   JProgressBar fliterLoadBar;   JButton okButton;   JButton cancelButton;   private void jbInit() throws Exception {      Box b = Box.createVerticalBox();      JLabel bannerLabel = new JLabel("3G資料過濾查詢");      b.add(bannerLabel);      //-------------setTheInputPanel------------------------------      JPanel inputPanel = new JPanel();      TitledBorder inputPanelBorder = new TitledBorder("設定參數");      inputPanelBorder.setTitleFont(defaultFont);      inputPanel.setBorder(inputPanelBorder);      Box vtemp = Box.createVerticalBox();      Box htemp1 = Box.createHorizontalBox();      Box htemp2 = Box.createHorizontalBox();      Box htemp3 = Box.createHorizontalBox();      Box htemp4 = Box.createHorizontalBox();      Box htemp5 = Box.createHorizontalBox();      Box htemp6 = Box.createHorizontalBox();      Box htemp7 = Box.createHorizontalBox();      Box htemp8 = Box.createHorizontalBox();      xTextField = new JTextField();      xTextField.setPreferredSize(new Dimension(50, 10));      htemp1.add(new JLabel("橫向:"));      htemp1.add(Box.createHorizontalStrut(10));     //建立label和textFied之間的距離      htemp1.add(xTextField);      htemp1.add(new JLabel("(例:3.01)"));      yTextField = new JTextField();      yTextField.setPreferredSize(new Dimension(50, 10));      htemp2.add(new JLabel("縱向:"));                   htemp2.add(Box.createHorizontalStrut(10));      htemp2.add(yTextField);      htemp2.add(new JLabel("(例:4.01)"));      zTextField = new JTextField();      zTextField.setPreferredSize(new Dimension(50, 10));      htemp3.add(new JLabel("垂直:"));      htemp3.add(Box.createHorizontalStrut(10));      htemp3.add(zTextField);      htemp3.add(new JLabel("(例:3.01)"));      inteTextField = new JTextField();      inteTextField.setPreferredSize(new Dimension(50, 10));      htemp4.add(new JLabel("綜合:"));      htemp4.add(Box.createHorizontalStrut(10));      htemp4.add(inteTextField);      htemp4.add(new JLabel("(例:5.01)"));      fliterStartTimeButton = new DateChooserJButton();      JLabel tmpLabel = new JLabel("開始時間:");      htemp5.add(tmpLabel);      htemp5.add(fliterStartTimeButton);      fliterEndTimeButton = new DateChooserJButton();      JLabel tmpLabel2 = new JLabel("結束時間:");      htemp6.add(tmpLabel2);      htemp6.add(fliterEndTimeButton);      fliterLoadBar = new JProgressBar();      JLabel tmpLabel3 = new JLabel("進度:");      htemp7.add(tmpLabel3);      htemp7.add(fliterLoadBar);      okButton = new JButton("過濾");      cancelButton = new JButton("撤銷");      htemp8.add(okButton);      htemp8.add(Box.createHorizontalStrut(10));      htemp8.add(cancelButton);      vtemp.add(htemp1);      vtemp.add(Box.createVerticalStrut(10));                  //建立上下空間距離      vtemp.add(htemp2);      vtemp.add(Box.createVerticalStrut(10));      vtemp.add(htemp3);      vtemp.add(Box.createVerticalStrut(10));      vtemp.add(htemp4);      vtemp.add(Box.createVerticalStrut(10));      vtemp.add(htemp5);      vtemp.add(Box.createVerticalStrut(10));      vtemp.add(htemp6);      vtemp.add(Box.createVerticalStrut(25));      vtemp.add(htemp7);      vtemp.add(Box.createVerticalStrut(5));      vtemp.add(htemp8);      inputPanel.add(vtemp);      //----------------------------------------------------------      //------------other panel init here-------------------------      //initCode!      //----------------------------------------------------------      b.add(inputPanel);      //b.add(otherPanel);      this.add(b, BorderLayout.NORTH);   }   public Fliter3GPanel() {      try {         jbInit();      }      catch (Exception ex) {         ex.printStackTrace();      }   }}

 

代碼如下:

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.