【发布时间】:2020-09-14 09:02:18
【问题描述】:
我在 Jython 中创建了一个 javaFX 选择器文件。从 Java 移植到 Jython 并不容易,但最终还是取得了一些成果。现在我想对获得的类进行参数化,考虑到文件过滤器,以便能够使用与过滤文件类型不同的对象进行浏览。
我试图插入一个固定的过滤器:
import sys
from javafx.application import Application
from javafx.stage import FileChooser, Stage
class fileBrowser(Application):
@classmethod
def main(cls, args):
fileBrowser.launch(cls, args)
def start(self, primaryStage):
fc = FileChooser()
filter = FileChooser.ExtensionFilter("All Images", '*.jpg')
fc.getExtensionFilters().add(
filter
)
f = fc.showOpenDialog(primaryStage)
if __name__ == '__main__':
fileBrowser.main(sys.argv)
但我有以下错误:
Exception in Application start method
Traceback (most recent call last):
File "provaFileChooser.py", line 28, in <module>
fileBrowser.main(sys.argv)
File "provaFileChooser.py", line 15, in main
fileBrowser.launch(cls, args)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: Traceback (most recent call last):
File "provaFileChooser.py", line 19, in start
filter = FileChooser.ExtensionFilter("JPG Images", '*.jpg')
TypeError: javafx.stage.FileChooser$ExtensionFilter(): 2nd arg can't be coerced to java.util.List, String[]
at org.python.core.Py.TypeError(Py.java:236)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:213)
at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:316)
at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:325)
java.lang.RuntimeException: java.lang.RuntimeException: Exception in Application start method
我还尝试将过滤器转换为列表并将过滤器插入列表,但错误仍然存在。
我做错了什么,我该怎么办?
提前致谢。
【问题讨论】: