[英]RxTx on JavaFX - Clearing comboBox
I'm making a QC-softare for our manufacturing facilities. 我正在为我们的制造工厂进行质量控制软件。 I am not a specialist in programming as I majored in Mechanical Engineering but I get go wear a lot of hats here and I love a good challenge.
我不是机械工程专业的编程专家,但是我在这里戴着很多帽子,我喜欢一个很好的挑战。 Anyways, I've been reading a lot of tutorials on RXTX and examples and finally made a good working program.
无论如何,我已经阅读了很多有关RXTX的教程和示例,并最终制定了一个不错的程序。 There's some issues that need polishing but overall it works.
有一些问题需要完善,但总的来说是可行的。 One of these issues is on the combobox where I list the "available ports" that it finds for serial COMM communication: Note: main.ports is an Enumeration
这些问题之一是在组合框上,在其中列出了它为串行COMM通信找到的“可用端口”:注意:main.ports是一个枚举
// SCAN METHOD
public void doScan(ActionEvent event) {
System.out.println("You clicked Scan");
doClearCBox();
main.ports = CommPortIdentifier.getPortIdentifiers();
//CLEAR COMBO BOX EVERY TIME YOU SCAN
while (main.ports.hasMoreElements())
{
CommPortIdentifier curPort = (CommPortIdentifier)main.ports.nextElement();
//get only serial ports
if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
main.portMap.put(curPort.getName(), curPort);
portList.getItems().add(curPort.getName());
}
}
}
public void doClearCBox()
{
System.out.println("Clearing combo box and Enumeration");
main.ports = null;
//JUST CLEAR RANDOM VALUES OR SOMETHING?
portList.getSelectionModel().clearSelection(0);
portList.getSelectionModel().clearSelection(1);
portList.getSelectionModel().clearSelection(2);
portList.getSelectionModel().clearSelection();
}
The problem I encounter is that if you press the "Scan" Button more than once it basically repeats everything (so for example you will see a list that says COM3, COM3) and if you click it 5 times you'll see (COM3, COM3, COM3, COM3, COM3). 我遇到的问题是,如果您多次按下“扫描”按钮,它将基本上重复所有操作(例如,您将看到一个显示COM3,COM3的列表),并且单击5次就会看到(COM3, COM3,COM3,COM3,COM3)。 My doClearCbox method does nothing apparently, I want it to de-populate the combobox and I can't get it to work.
我的doClearCbox方法显然没有执行任何操作,我希望它删除组合框,而我无法使其正常工作。 Any help is greatly appreciated
任何帮助是极大的赞赏
The selectionModel
in a combo box (and other controls) manages what is currently selected. 组合框(和其他控件)中的
selectionModel
管理当前选择的内容。 So 所以
portList.getSelectionModel().clearSelection(index);
just deselects the item at index
. 只是取消选择
index
处的项目 。
The combo box's getItems()
method returns the list of items in the combo box. 组合框的
getItems()
方法返回组合框中的项目列表。 So if you want to clear all the items, you do 因此,如果您想清除所有项目,则可以
portList.getItems().clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.