我创建了一个Java实用程序,在x内部的x花式zip文件(twx)中搜索XML.
最初这是一个命令行实用程序,没有线程.
当我将其移动到使用JavaFX时,我遇到了冻结问题,然后将所有搜索移动到Task对象中进行修复.
我需要一些方法来跟踪进度,所以我实现了Progress属性和ProgressBar来跟踪.
它工作得很好,但由于我已经是多线程,为什么不为每个Zip搜索创建一个线程.不幸的是,这种方法效果不佳.
为了跟踪我创建一个任务数组,然后创建一个处理它们的主任务.我使用处理所有更新的进度和总属性.
这是代码
public class TextSearch {
final private SimpleDoubleProperty progress = new SimpleDoubleProperty();
final private SimpleDoubleProperty total = new SimpleDoubleProperty();
/**
*
* Kicks off a search. Creates a Task/Thread for each twx search.
* @return A task object that maintains all of the twx searches.
*
* @throws ZipException If the zip file is unreadable.
* @throws IOException If the file is unreadable.
* @throws JDOMException If the xml in the files are unreadable. …Run Code Online (Sandbox Code Playgroud) 右键单击TextField时,有"撤消","重做","剪切","复制","粘贴","删除"和"全选"选项.
我想从我的控制器类添加一个"Register"MenuItem到该列表,但不知道如何.
这是我到目前为止所得到的:
这会覆盖现有的菜单项:
ContextMenu contextMenu = new ContextMenu();
MenuItem register = new MenuItem("Register");
contextMenu.getItems().add(register);
charName.setContextMenu(contextMenu);
Run Code Online (Sandbox Code Playgroud)
这两个都返回null:
charName.getContextMenu()
charName.contextMenuProperty().getValue()
Run Code Online (Sandbox Code Playgroud)