我很难将自定义NSToolbarItem添加到现有工具栏。
NSToolbar是在NSWindowController中创建的,然后我有一个函数以编程方式填充工具栏项,代码为:
public func populateFileToolbarItem(_ toolbar: NSToolbar) -> Void{
let itemId = NSToolbarItem.Identifier("FILE_OPEN")
let index = toolbar.items.count
var toolbarItem: NSToolbarItem
toolbarItem = NSToolbarItem(itemIdentifier: itemId)
toolbarItem.label = String("File")
toolbarItem.paletteLabel = String("Open File")
toolbarItem.toolTip = String("Open file to be handled")
toolbarItem.tag = index
toolbarItem.target = self
toolbarItem.isEnabled = true
toolbarItem.action = #selector(browseFile)
toolbarItem.image = NSImage.init(named:NSImage.folderName)
toolbar.insertItem(withItemIdentifier: itemId, at: index)
}
Run Code Online (Sandbox Code Playgroud)
然后我调用了此函数,将工具栏项添加到windowController中的现有工具栏
.......
populateFileToolbarItem((self.window?.toolbar)!)
self.window?.toolbar?.insertItem(withItemIdentifier: NSToolbarItem.Identifier.flexibleSpace, at: (self.window?.toolbar?.items.count)!)
self.window?.toolbar?.insertItem(withItemIdentifier: NSToolbarItem.Identifier.print, at: (self.window?.toolbar?.items.count)!)
print("after toolbaritems were inserted into toolbar. \(String(describing: self.window?.toolbar?.items.count))")
......
Run Code Online (Sandbox Code Playgroud)
控制台打印输出显示,工具栏仅添加了两个工具栏项。
....... …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Oracle JDK 11 应用程序迁移到 JDK 17.0.7,当我尝试访问 java.utils.Set 中的 add() 时,它抛出
java.lang.UnsupportedOperationException
Run Code Online (Sandbox Code Playgroud)
我查了一下Stackoverflow,发现java.util.Set的实现还没有完全支持add()函数,它被标记为可选。
我的问题是,哪个 java 供应商的 Java 17 已经支持或实现了 java Set add() 方法?
我的应用程序中有相当多的 Java 对象需要这个函数。
如果有人有想法,请指教。