我java代码中的下拉列表设好后为什么无法下拉?
packageFAA;importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.FlowLa...
package FAA;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import javax.swing.text.AbstractDocument.Content;
public class FAIM extends JFrame {
JLabel lblLocation = new JLabel("坐落位置");
JLabel lblBuildTime = new JLabel("建成年代");
JLabel lblUsage = new JLabel("房屋用途");
JLabel lblNumber = new JLabel("房屋套数");
JLabel lblType = new JLabel("房屋类型");
JLabel lblArea = new JLabel("建筑面积");
JLabel lblUsageArea = new JLabel("使用面积");
JTextField txtLocation = new JTextField(30);
JTextField txtBuildTime = new JTextField(8);
JTextField txtNumber = new JTextField(8);
JTextField txtArea = new JTextField(8);
JTextField txtUsageArea = new JTextField(8);
JComboBox cmbUsage = new JComboBox();
JComboBox cmbType = new JComboBox();
JButton btnAdd = new JButton("新增");
JButton btnUpdate = new JButton("修改");
JButton btnDel = new JButton("删除");
JButton btnSave =new JButton("保存");
JButton btnExit = new JButton("退出");
FAIM(String title)
{
super(title);
Container p = getContentPane();
p.setLayout(new BorderLayout());
Panel pCenter = new Panel(new GridLayout(3,4));
Panel pNorth = new Panel(new FlowLayout(FlowLayout.LEFT));
Panel pSouth = new Panel(new FlowLayout());
pNorth.add(lblLocation);pNorth.add(txtLocation);
pCenter.add(lblBuildTime);pCenter.add(txtBuildTime);
pCenter.add(lblUsage);pCenter.add(cmbUsage);
pCenter.add(lblNumber);pCenter.add(txtNumber);
pCenter.add(lblType);pCenter.add(cmbType);
pCenter.add(lblArea);pCenter.add(txtArea);
pCenter.add(lblUsageArea);pCenter.add(txtUsageArea);
pSouth.add(btnAdd);pSouth.add(btnUpdate);pSouth.add(btnDel);
pSouth.add(new JLabel(" "));pSouth.add(btnSave);pSouth.add(btnExit);
p.add(pNorth,"North");p.add(pSouth,"South");
p.add(pCenter);
pack();
int FrWidth = getWidth();int FrHeight = getHeight();
int SrcWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int SrcHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation((SrcWidth-FrWidth)/2, (SrcHeight-FrHeight)/2);
//db.initCombo(cmbUsage, "HouseUsage");
//db.initCombo(cmbType, "HouseType");
cmbUsage.addItem(1);cmbUsage.addItem(2);
cmbType.addItem(1);cmbType.addItem(2);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
new FAIM("房产信息维护");
}
} 展开
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import javax.swing.text.AbstractDocument.Content;
public class FAIM extends JFrame {
JLabel lblLocation = new JLabel("坐落位置");
JLabel lblBuildTime = new JLabel("建成年代");
JLabel lblUsage = new JLabel("房屋用途");
JLabel lblNumber = new JLabel("房屋套数");
JLabel lblType = new JLabel("房屋类型");
JLabel lblArea = new JLabel("建筑面积");
JLabel lblUsageArea = new JLabel("使用面积");
JTextField txtLocation = new JTextField(30);
JTextField txtBuildTime = new JTextField(8);
JTextField txtNumber = new JTextField(8);
JTextField txtArea = new JTextField(8);
JTextField txtUsageArea = new JTextField(8);
JComboBox cmbUsage = new JComboBox();
JComboBox cmbType = new JComboBox();
JButton btnAdd = new JButton("新增");
JButton btnUpdate = new JButton("修改");
JButton btnDel = new JButton("删除");
JButton btnSave =new JButton("保存");
JButton btnExit = new JButton("退出");
FAIM(String title)
{
super(title);
Container p = getContentPane();
p.setLayout(new BorderLayout());
Panel pCenter = new Panel(new GridLayout(3,4));
Panel pNorth = new Panel(new FlowLayout(FlowLayout.LEFT));
Panel pSouth = new Panel(new FlowLayout());
pNorth.add(lblLocation);pNorth.add(txtLocation);
pCenter.add(lblBuildTime);pCenter.add(txtBuildTime);
pCenter.add(lblUsage);pCenter.add(cmbUsage);
pCenter.add(lblNumber);pCenter.add(txtNumber);
pCenter.add(lblType);pCenter.add(cmbType);
pCenter.add(lblArea);pCenter.add(txtArea);
pCenter.add(lblUsageArea);pCenter.add(txtUsageArea);
pSouth.add(btnAdd);pSouth.add(btnUpdate);pSouth.add(btnDel);
pSouth.add(new JLabel(" "));pSouth.add(btnSave);pSouth.add(btnExit);
p.add(pNorth,"North");p.add(pSouth,"South");
p.add(pCenter);
pack();
int FrWidth = getWidth();int FrHeight = getHeight();
int SrcWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int SrcHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation((SrcWidth-FrWidth)/2, (SrcHeight-FrHeight)/2);
//db.initCombo(cmbUsage, "HouseUsage");
//db.initCombo(cmbType, "HouseType");
cmbUsage.addItem(1);cmbUsage.addItem(2);
cmbType.addItem(1);cmbType.addItem(2);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
new FAIM("房产信息维护");
}
} 展开
2个回答
展开全部
pCenter, pNorth, pSouth不要用Panel,用JPanel。Awt和Swing的控件在层次结构上不要混用(在其他情况下也建议不要混用)。
==== 修改后的代码 ====
package FAA;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FAIM extends JFrame {
JLabel lblLocation = new JLabel("坐落位置");
JLabel lblBuildTime = new JLabel("建成年代");
JLabel lblUsage = new JLabel("房屋用途");
JLabel lblNumber = new JLabel("房屋套数");
JLabel lblType = new JLabel("房屋类型");
JLabel lblArea = new JLabel("建筑面积");
JLabel lblUsageArea = new JLabel("使用面积");
JTextField txtLocation = new JTextField(30);
JTextField txtBuildTime = new JTextField(8);
JTextField txtNumber = new JTextField(8);
JTextField txtArea = new JTextField(8);
JTextField txtUsageArea = new JTextField(8);
JComboBox cmbUsage = new JComboBox();
JComboBox cmbType = new JComboBox();
JButton btnAdd = new JButton("新增");
JButton btnUpdate = new JButton("修改");
JButton btnDel = new JButton("删除");
JButton btnSave = new JButton("保存");
JButton btnExit = new JButton("退出");
FAIM(String title) {
super(title);
Container p = getContentPane();
p.setLayout(new BorderLayout());
JPanel pCenter = new JPanel(new GridLayout(3, 4));
JPanel pNorth = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel pSouth = new JPanel(new FlowLayout());
pNorth.add(lblLocation);
pNorth.add(txtLocation);
pCenter.add(lblBuildTime);
pCenter.add(txtBuildTime);
pCenter.add(lblUsage);
pCenter.add(cmbUsage);
pCenter.add(lblNumber);
pCenter.add(txtNumber);
pCenter.add(lblType);
pCenter.add(cmbType);
pCenter.add(lblArea);
pCenter.add(txtArea);
pCenter.add(lblUsageArea);
pCenter.add(txtUsageArea);
pSouth.add(btnAdd);
pSouth.add(btnUpdate);
pSouth.add(btnDel);
pSouth.add(new JLabel(" "));
pSouth.add(btnSave);
pSouth.add(btnExit);
p.add(pNorth, "North");
p.add(pSouth, "South");
p.add(pCenter);
pack();
int FrWidth = getWidth();
int FrHeight = getHeight();
int SrcWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int SrcHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation((SrcWidth - FrWidth) / 2, (SrcHeight - FrHeight) / 2);
// db.initCombo(cmbUsage, "HouseUsage");
// db.initCombo(cmbType, "HouseType");
cmbUsage.addItem(1);
cmbUsage.addItem(2);
cmbType.addItem(1);
cmbType.addItem(2);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
new FAIM("房产信息维护");
}
}
==== 修改后的代码 ====
package FAA;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FAIM extends JFrame {
JLabel lblLocation = new JLabel("坐落位置");
JLabel lblBuildTime = new JLabel("建成年代");
JLabel lblUsage = new JLabel("房屋用途");
JLabel lblNumber = new JLabel("房屋套数");
JLabel lblType = new JLabel("房屋类型");
JLabel lblArea = new JLabel("建筑面积");
JLabel lblUsageArea = new JLabel("使用面积");
JTextField txtLocation = new JTextField(30);
JTextField txtBuildTime = new JTextField(8);
JTextField txtNumber = new JTextField(8);
JTextField txtArea = new JTextField(8);
JTextField txtUsageArea = new JTextField(8);
JComboBox cmbUsage = new JComboBox();
JComboBox cmbType = new JComboBox();
JButton btnAdd = new JButton("新增");
JButton btnUpdate = new JButton("修改");
JButton btnDel = new JButton("删除");
JButton btnSave = new JButton("保存");
JButton btnExit = new JButton("退出");
FAIM(String title) {
super(title);
Container p = getContentPane();
p.setLayout(new BorderLayout());
JPanel pCenter = new JPanel(new GridLayout(3, 4));
JPanel pNorth = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel pSouth = new JPanel(new FlowLayout());
pNorth.add(lblLocation);
pNorth.add(txtLocation);
pCenter.add(lblBuildTime);
pCenter.add(txtBuildTime);
pCenter.add(lblUsage);
pCenter.add(cmbUsage);
pCenter.add(lblNumber);
pCenter.add(txtNumber);
pCenter.add(lblType);
pCenter.add(cmbType);
pCenter.add(lblArea);
pCenter.add(txtArea);
pCenter.add(lblUsageArea);
pCenter.add(txtUsageArea);
pSouth.add(btnAdd);
pSouth.add(btnUpdate);
pSouth.add(btnDel);
pSouth.add(new JLabel(" "));
pSouth.add(btnSave);
pSouth.add(btnExit);
p.add(pNorth, "North");
p.add(pSouth, "South");
p.add(pCenter);
pack();
int FrWidth = getWidth();
int FrHeight = getHeight();
int SrcWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int SrcHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation((SrcWidth - FrWidth) / 2, (SrcHeight - FrHeight) / 2);
// db.initCombo(cmbUsage, "HouseUsage");
// db.initCombo(cmbType, "HouseType");
cmbUsage.addItem(1);
cmbUsage.addItem(2);
cmbType.addItem(1);
cmbType.addItem(2);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
new FAIM("房产信息维护");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |