在jComboBox中列出Comport

时间:2015-03-04 08:49:37

标签: java serial-port jcombobox enumeration

Debug我正在尝试使用我系统中可用Comports的列表填充jComboBox。下面是我试图实现这个,但当我点击ComboBox仍然是空的。这是否在正确的上下文中用作ActionPerformed?

public void comPortcomboBoxActionPerformed(java.awt.event.ActionEvent evt) {

        Enumeration portList = CommPortIdentifier.getPortIdentifiers();


        while (portList.hasMoreElements()) {
          CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();

          if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            comPortcomboBox.setEnabled(true);
            comPortcomboBox.addItem(cpi.getName());
            resultsTextArea.setText(cpi.getName());
            }


          }
     }

0 个答案:

没有答案