【发布时间】:2016-04-30 22:15:24
【问题描述】:
我想打开一个 pdf 文件并在单击按钮时将其显示在新窗口中 我试试这个,它不起作用:
Button btn = new Button();
File file=new File("Desktop/Test.pdf");
btn.setText("Open");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
desktop.open(file);
} catch (IOException ex) {
Logger.getLogger(Exemple.class.getName())
.log(Level.SEVERE, null, ex);
}
}
});
【问题讨论】:
-
什么是
desktop? “不工作”是什么意思? -
桌面桌面 = Desktop.getDesktop();
-
找不到文件,但我把它放在桌面上
-
试试
new File(System.getProperty("user.home"), "Desktop/Test.pdf")