用Box布局swing界面

帮程序添加了一个小模块~~画界面用Box布局管理器,觉得用起来挺方便的~~

这里介绍给还没使用的朋友~~ 

 主要就用到了这四个方法

 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();
      }
   }

}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值