Skip to content

Commit fc71eb6

Browse files
committed
v0.0.2 -- ensure JavaFX is loaded
1 parent b170b8d commit fc71eb6

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/beast/app/shell/BEASTStudio.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import java.awt.event.WindowAdapter;
1313
import java.awt.event.WindowEvent;
1414
import java.io.File;
15+
import java.io.IOException;
1516
import java.lang.reflect.Method;
17+
import java.net.MalformedURLException;
1618
import java.net.URL;
1719

1820
import javax.swing.Action;
@@ -30,6 +32,7 @@
3032

3133
import beast.app.draw.MyAction;
3234
import beast.app.util.Utils;
35+
import beast.util.AddOnManager;
3336
import bsh.BshClassManager;
3437
import bsh.ClassPathException;
3538
import bsh.NameSource;
@@ -366,10 +369,52 @@ private JMenuBar createMenuBar() {
366369

367370
return menuBar;
368371
}
369-
372+
373+
private static void loadJavaFX() {
374+
try {
375+
// JavaFX already loaded?
376+
Class x = Class.forName("javafx.embed.swing.JFXPanel");
377+
// if we got here, all is fine.
378+
return;
379+
} catch (ClassNotFoundException e) {
380+
// JavaFX is not loaded yet
381+
try {
382+
String home = System.getenv("JAVA_HOME");
383+
if (home != null) {
384+
AddOnManager.addURL(new URL("file:" + home + "/jre/lib/jfxrt.jar"));
385+
Class.forName("javafx.embed.swing.JFXPanel");
386+
return;
387+
}
388+
String jarfile = System.getenv("JAVAFX_JAR");
389+
if (jarfile != null) {
390+
AddOnManager.addURL(new URL("file:" + jarfile));
391+
Class.forName("javafx.embed.swing.JFXPanel");
392+
return;
393+
}
394+
File f = new File("/opt/java/jre/lib/jfxrt.jar");
395+
if (f.exists()) {
396+
AddOnManager.addURL(new URL("file:" + f.getPath()));
397+
Class.forName("javafx.embed.swing.JFXPanel");
398+
return;
399+
}
400+
} catch (MalformedURLException e1) {
401+
e1.printStackTrace();
402+
} catch (IOException e1) {
403+
e1.printStackTrace();
404+
} catch (ClassNotFoundException e1) {
405+
e1.printStackTrace();
406+
}
407+
}
408+
JOptionPane.showMessageDialog(null, "Could not load JavaFX. Run with java 7 or higher, or set the JAVAFX_JAR environment variable to the location of jfxrt.jar or install jfxrt.jar at /opt/java/jre/lib/jfxrt.jar. -- exiting now");
409+
System.exit(0);
410+
}
411+
370412
public static void main(String[] args) {
371413
bsh.util.Util.startSplashScreen();
372-
414+
415+
// try to load JavaFX
416+
loadJavaFX();
417+
373418
JFrame frame = new JFrame();
374419
final BEASTStudio studio = new BEASTStudio(args);
375420
studio.setup();
227 Bytes
Binary file not shown.

src/bsh/util/lib/splash.jpg

58 Bytes
Loading

0 commit comments

Comments
 (0)