我正在尝试使用我系统中可用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());
}
}
}