写好的箱式布局,如何调整?
我要调整:
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.控件的大小,如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);
}
解决方案 »
- 江湖救急啊!菜鸟求救!
- 也许高手一看便知的问题:socket和线程释放问题
- 学JAVA选JB好还是VJ#好?请资深的JAVA程序员给点意见。谢谢!!
- 帮忙看段代码~~~
- 怎么以追加的方式打开文件啊?或者怎样往文件的末尾加入一行?
- 为什么不显示滚动条啊?(在线等)
- 怎么做带有checkbox的Tree控件?
- 不算复杂但很麻烦的JAVA编译和运行如何通过鼠标右键来实现???
- 为什么我在JBuilder中编译所有的程序都提示输出路径错误?即使书上的例程
- 大侠们:谁能教我JAVA 入门?不胜感激!!!!
- 关于java.io.EOFException的问题?????
- 对应于数据库中的 Date的 java数据类型是 什么?
改为datefromJLabel = new JLabel("日期从 ");
给它的初值多几个" "就好啦你的布局有点乱