在组合框上实现新窗口

时间:2019-03-27 11:12:14

标签: java swing

当我从下拉列表中选择一项时,我想实现并打开新窗口。但是,当我在if / else中使用getSelectedItem时-想要在应用程序中选择条目时会编译但返回错误。问题出在哪里?

public class TemplatesList extends JComboBox<String>
{
    public String[] lista = {"change request", "emergancy change request", "problem request","problem handover", "Major Incident handover" };
    public JComboBox faceCombo;
    String e;


    public TemplatesList()
    {
        //faceCombo = new JComboBox();
        for (int i=0; i < lista.length; i++)
        {
            this.addItem(lista[i]);
        }
        addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            if (faceCombo.getSelectedItem() == "change request"){
                SecondWindow regFace = new SecondWindow();
                regFace.setVisible(true);
            } else {

            }
        }
    });
    }
}

1 个答案:

答案 0 :(得分:0)

您可以在此处添加项目侦听器,然后检查所选项目,具体取决于您可以使面板或显示对话框可见。