如何从java中的组合框获取文本

时间:2017-12-08 15:20:40

标签: java jcombobox

String itemcodes[] = {"082413358502", "082401358502", "082396358502", "082395358502", "082392338302",
            "082387338302", "082376358502", "052396200206", "052389200206", "051376200302",
            "051369200302", "051363200302", "051352200302", "051331300002", "022137000051",
            "022131000051", "022130000051", "022128000051"};
    JComboBox<String> comboBox = new JComboBox<>(itemcodes);
    comboBox.setBounds(194, 67, 222, 20);
    contentPane.add(comboBox);
    comboBox.setEditable(true);        
    //contentPane.

    JButton btnNewButton = new JButton("New button");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            String itmee = comboBox.getText();
            //String itemee = textFieldItem.getText();
            String len = textField_1.getText();
            sqll.Reader(itemee,len);
            poi.Poi_();
        }

如何在组合框中选择文本,以便将其存储在itmee变量中。

1 个答案:

答案 0 :(得分:0)

由于您的组合框是可编辑的,因此即使在编辑器失去焦点之前,此方法也会为您提供当前键入的文本:

combobox.getEditor().getItem()