[英]How can I bring the program behind the pop up window?
As you can see below in my code when clicks on the helpsection
method a PDF file opens. 如下面在我的代码中看到的,当单击helpsection
方法时,将打开一个PDF文件。 I was wondering instead of the PDF being behind the program, how can I bring that window in front of the program? 我想知道不是将PDF放在程序后面,如何将该窗口放在程序前面? I tried using Desktop.setVisible(true);
我尝试使用Desktop.setVisible(true);
However, I had no luck I got the error messages. 但是,我没有走运我得到错误消息。
PROGRAM CODE 程序代码
import java.util.Scanner; //taking input from user
import java.io.File;
import java.awt.Desktop;
public static void helpsection() {
try {
Desktop.getDesktop().open(new File("CVliamdocherty.pdf"));
Desktop.setVisible(true);
} catch(Exception e) {
System.out.println(e);
}
System.out.println("Would you like to go back into the program to select a course to find out your grade?");
System.out.println("You can enter 'Yes' or 'No' only.");
outcome2 = userinput.next();
if (outcome2.equalsIgnoreCase("Yes")) {
step1();
} else if (outcome2.equalsIgnoreCase("No")) {
System.out.println((username)+" thanks for using Liam's UCAS grade calculator.");
System.exit(0);
} else {
System.out.println("You have entered an invalid value.");
System.out.println("The program now will re run, make sure to enter the correct value next time.");
step1();
}
}
Try this to open your pdf doucument using default pdf viewer 尝试使用默认的pdf查看器打开pdf文件
Desktop desktop = Desktop.getDesktop();
desktop.open(new File("CVliamdocherty.pdf"));
I haven't tried your code because I'm currently using Linux and it requires one to use xdg-open to open a document with default application. 我没有尝试过您的代码,因为我当前正在使用Linux,它需要使用xdg-open才能使用默认应用程序打开文档。 So just try and see if it works 所以只要尝试看看是否可行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.