我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("房产信息维护");
}

}
展开
 我来答
百度网友6d408b6
2007-10-08 · TA获得超过1726个赞
知道小有建树答主
回答量:402
采纳率:0%
帮助的人:487万
展开全部
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("房产信息维护");
    }

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
19870314wang
2007-10-08
知道答主
回答量:31
采纳率:0%
帮助的人:0
展开全部
用swing中的list
之后在用additem()加选项
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式