写好的箱式布局,如何调整?
我要调整:
1.控件的大小,如JComboBox的大小,JLable的大小
2 控件间横向的间距import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;import java.sql.*;public class sale
    extends JFrame
    implements ActionListener {
  JPanel inputJPanel;
  JMenuBar mubar;
JMenu inputmu;
  JMenuItem inputmuit; //inputmuitJButton ookJButton;
//input windows
  inpt inp;
  JButton okJButton, nextJButton;
  JTextField sumJTextField;
  public sale() {
    createUserInterface();
  }  // create and position GUI components
  private void createUserInterface() {    inp=new  inpt(this);
    this.getContentPane().add(inp, BorderLayout.WEST);
//contentPane.add(inp);
    mubar = new JMenuBar();
    setJMenuBar(mubar);
    inputmu = new JMenu("输入");
    inputmu.setFont(new Font("SansSerif", Font.PLAIN, 15));
    mubar.add(inputmu);    inputmuit = new JMenuItem("输入");
    inputmuit.setFont(new Font("SansSerif", Font.PLAIN, 15));
    inputmu.add(inputmuit);
    inputmuit.addActionListener(inp);
    setTitle("sale"); // set title bar text
    setSize(435, 390); // set window size
    setVisible(true); // display window  }  private void okJButtonactionPerformed(ActionEvent e) {    sumJTextField.setText("");
  }  public void actionPerformed(ActionEvent e) {  }  public static void main(String[] args) {
    sale application = new sale();    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  } // end method main
}
//input
  class inpt extends JPanel implements ActionListener  {
JButton okJButton;
JLabel datefromJLabel,  datetoJLabel;
   JComboBox  datefromyJComboBox,datefrommJComboBox,datetoyJComboBox;
    sale s;    inpt(sale s) {
      this.s = s;
       createUserInterface();    }
 private void createUserInterface() {
   BorderLayout layout = new BorderLayout();
        setLayout(layout);     
 okJButton = new JButton("输入完毕,添加到数据库");
    okJButton.setFont(new Font("SansSerif", Font.PLAIN, 15));
    okJButton.setBounds(150, 280, 200, 30);
    okJButton.setVisible(false);    okJButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
       // okJButtonactionPerformed(e);
      }
    }
    );
   
   
   
    datefromJLabel = new JLabel("日期从");
    datefromJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
    datefromJLabel.setVisible(false);
  datetoJLabel = new JLabel("日期到");
    datetoJLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
    datetoJLabel.setVisible(false);
   
   
   
   
       datefromyJComboBox = new JComboBox();
    datefromyJComboBox.setFont(new Font("SansSerif", Font.PLAIN, 15));
    datefromyJComboBox.setMaximumSize( datefromyJComboBox.getPreferredSize());
    datefromyJComboBox.setVisible(false);
   datefrommJComboBox = new JComboBox();
    datefrommJComboBox.setFont(new Font("SansSerif", Font.PLAIN, 15));
    datefrommJComboBox.setMaximumSize( datefrommJComboBox.getPreferredSize());
    datefrommJComboBox.setVisible(false);
   
    datetoyJComboBox = new JComboBox();
   // datetoyJComboBox.setBounds(80, 70, 60, 40);
     datetoyJComboBox.setMaximumSize( datetoyJComboBox.getPreferredSize());
    datetoyJComboBox.setFont(new Font("SansSerif", Font.PLAIN, 15));
    datetoyJComboBox.setVisible(false);
   
   Box hbox1 = Box.createHorizontalBox();//水平
 Box hbox2 = Box.createHorizontalBox(); 
       hbox1.add(datefromJLabel);
     hbox1.createHorizontalStrut(30);
 
    
   //  hbox1.add(Box.createHorizontalGlue());//弹簧   
      // hbox1.createHorizontalStrut(60);
           hbox1.add(datefromyJComboBox);
      // hbox1.add(datefrommJComboBox); 
        hbox2.add(Box.createVerticalStrut(60));//支撑柱
        //hbox2.add(Box.createRigidArea(new Dimension(10, 10)));//固定区 10是箱子的大小
       // hbox2.createHorizontalGlue() ;//胶水
       hbox2.add(datetoJLabel);
        hbox1.add(Box.createHorizontalGlue());
       hbox2.createHorizontalStrut(60)   ;
       hbox2.add(datetoyJComboBox);        Box vbox = Box.createVerticalBox();//垂直
        vbox.add(Box.createVerticalStrut(70));
        vbox.add(hbox1);        vbox.add(Box.createVerticalStrut(70));
        vbox.add(hbox2);
        add(vbox);  }
    public void actionPerformed(ActionEvent e) {
      if (e.getSource() == s.inputmuit)
          okJButton.setVisible(true);      datefromJLabel.setVisible(true);
      datetoJLabel.setVisible(true);      datefromyJComboBox.setVisible(true);
   datefrommJComboBox.setVisible(true);      datetoyJComboBox.setVisible(true);
     }

解决方案 »

  1.   

    呵呵,我在jbuilder中,要改的话先把layout转成xy,调好后再换回原来的layout...
      

  2.   

    diggywang(Miner Lover!说的什么意思,我不太明白,能帮我改下吗?
      

  3.   

    ailu5949() 说的打空格是什么意思,我根本打不了空格啊
      

  4.   

    datefromJLabel = new JLabel("日期从");
    改为datefromJLabel = new JLabel("日期从   ");
    给它的初值多几个"   "就好啦你的布局有点乱
      

  5.   

    我的布局就是很乱啊,不会弄啊因为我是把一个类的按钮什么的放在另外一个类里显示的,所以null布局不能用啊空格的办法对label还不错,就是别的那些控件都拉不开