在swing的网格布局中怎样合并两个单元格?
解决方案 »
- 请问1L+11为什么不等于12L
- JSF 中使用PreparedStatement的setString问题
- 如何精确得知哪些class被使用了?
- 对于初学者学JAVA该看些什么书呢?
- 如何监视文本编辑
- 困扰了小弟很久的播放器不能实例化的问题(自己写的一个播放器,还在建设中),有兴趣的可意见来看下,代码很长,小弟菜鸟一个,大家请多
- 安卓中写在oncreat里的一位数组怎么被引用
- 卖艺不卖身,有需要系统分析员的吗?兼职、合作都可以......
- 我又来给分了,清说说Vector的用法和特点,最好有例子。
- 能具体说说static的用处吗?
- 正则表达式--possessive问题
- 问一下正则表达式的效率
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.sessionFacrory.HibernateSessionFactory;public class Save extends JFrame {JTextField field1 = new JTextField(10);JComboBox box = new JComboBox();ComboBoxText ct = new ComboBoxText();JComboBox cb = new JComboBox();JComboBox ca = new JComboBox(ct.a());JTextField field5 = new JTextField(20);JTextField field6 = new JTextField(10);JButton button = new JButton("添加");JButton canel = new JButton("退出");JButton dispaly = new JButton("呵呵");JLabel label = new JLabel("姓名:");JLabel labe2 = new JLabel("性别:");JLabel labe3 = new JLabel("所在系:");JLabel labe4 = new JLabel("所在专业:");JLabel labe5 = new JLabel("地址:");JLabel labe6 = new JLabel("开始时间:");p1 p = new p1();Save() {
super("学生信息添加");
this.setSize(790, 140);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
GridLayout gridLayout = new GridLayout();
GridBagLayout bagLayout = new GridBagLayout();
// /gridLayout.removeLayoutComponent(button);
gridLayout.removeLayoutComponent(canel);
panel.setLayout(gridLayout);
JFrame f = new JFrame();
Container contentPane = f.getContentPane();
contentPane.setLayout(bagLayout);
box.addItem("男");
box.addItem("女");
box.setSelectedIndex(-1);
// Toolkit kit=Toolkit.getDefaultToolkit();//设置顶层容器框架为居中
Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = this.getSize();
setLocation((scr.width - frm.width) / 2, (scr.height - frm.height) / 2);// 窗体居中
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(20, 20, 20, 20);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 10;
c2.weightx = 0;
c2.weighty = 1.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(label, c2);
panel.add(label, c2);// panel.add(label);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 2;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
// bagLayout.setConstraints(field1, c2);
panel.add(field1, c2);
// panel.add(field1);c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 5;
c2.weightx = 20;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(labe2, c2);
panel.add(labe2, c2);
// panel.add(labe2);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 10;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(box, c2);
panel.add(box, c2);
// panel.add(box);c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 5;
c2.weightx = 20;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
// bagLayout.setConstraints(labe3, c2);
panel.add(labe3, c2);
// panel.add(labe3);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight =5;
c2.weightx = 20;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(ca, c2);
panel.add(ca, c2);
// panel.add(ca);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 6;
c2.weightx = 20;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(labe4, c2);
panel.add(labe4, c2);
// panel.add(labe4);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 20;
c2.gridheight = 5;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(cb, c2);
panel.add(cb, c2);
// panel.add(cb);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 20;
c2.gridheight = 5;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(labe5, c2);
panel.add(labe5, c2);
// panel.add(labe5);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 10;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(field5, c2);
panel.add(field5, c2);
// panel.add(field5);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 10;
c2.weightx = 10;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(labe6, c2);
panel.add(labe6, c2);
// panel.add(labe6);
c2.insets = new Insets(0, 0, 0, 0);
c2.gridx = 0;
c2.gridy = 0;
c2.gridwidth = 4;
c2.gridheight = 10;
c2.weightx = 0;
c2.weighty = 0.5;
c2.anchor = GridBagConstraints.WEST;
c2.fill = GridBagConstraints.NONE;
bagLayout.setConstraints(field6, c2);
panel.add(field6, c2);button.setVisible(false);
// panel.add(dispaly);
// dispaly.setVisible(false);
panel.add(button);
// panel.add(canel);
panel.add(p);
c2.fill = GridBagConstraints.NONE;
this.setContentPane(panel);
Container c = new Container();
c.remove(button);
c.remove(canel);
gridLayout.setColumns(8);
gridLayout.setRows(4);
gridLayout.setHgap(2);
gridLayout.setVgap(2);
c.setLayout(gridLayout);
// 下拉框处理
ca.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 清空选项框
cb.removeAllItems();
// 得到系的选项
Object selected = ca.getSelectedItem();
// 给专业赋值
Object[] newItems = ct.b(selected);
for (int i = 0; i < newItems.length; i++) {
cb.addItem(newItems[i]);
}}});
// 初始化系选项为-1
ca.setSelectedIndex(-1);}public class p1 extends JPanel {
p1() {
JButton das = new JButton("添加");
das.setSize(50, 50);
JButton das2 = new JButton("取消");
super.add(das);
super.add(das2);}
}public static void main(String[] args) {Save save = new Save();
save.show();
}
}
我想把 姓名这个label这列 和 文本框的距离缩短,怎么办啊?