JavaFX resource handling: Load HTML files in WebView

You get this exception because your url variable is null on this line: String url = WebViewSample.class.getResource(“/map.html”).toExternalForm(); You have several options with getResource(): If the resource is the same directory as the class, then you can use String url = WebViewSample.class.getResource(“map.html”).toExternalForm(); Using beginning slash(“https://stackoverflow.com/”) means relative path to the project root.: In your particular case, … Read more

Getting a mp3 file to play using javafx

The files located outside the workspace should be included with file:// prefix. A simple example demonstrating the functionality is public class Reproductor extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { Media media = new Media(“file:///Movies/test.mp3”); //replace /Movies/test.mp3 with your file MediaPlayer player = new … Read more

How to solve the “Graphics Device initialization failed for : d3d, sw” Problem

Download the JavaFX Windows SDK using the link below https://gluonhq.com/products/javafx/ and use the options below in VM argument’s when running FX Application -p $ModuleFileDir$/lib/javafx-sdk-11.0.2/lib –add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media,javafx.web –add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED –add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED Note: Don’t change anything in the downloaded folder: use as it is. The DLL files are important; if the DLL files are missing then the above … Read more

Setting font color of JavaFX TableView Cells?

You need to override the CellFactory. Partial code just of the third column: TableColumn thirdColumn = new TableColumn(“Third Column”); thirdColumn.setCellValueFactory(new PropertyValueFactory<TableData,String>(“three”)); // ** The TableCell class has the method setTextFill(Paint p) that you // ** need to override the text color // To obtain the TableCell we need to replace the Default CellFactory // with … Read more

JavaFx 8: open a link in a browser without reference to Application

Solution 1: Pass a reference to the HostServices down through your application. This is probably similar to the “quite painful” approach you are anticipating. But basically you would do something like: public void start(Stage primaryStage) throws Exception { FXMLLoader loader = new FXMLLoader(getClass().getResource(“main.fxml”)); Parent root = loader.load(); MainController controller = loader.getController(); controller.setHostServices(getHostServices()); primaryStage.setScene(new Scene(root)); primaryStage.show(); … Read more

JavaFX: Change application language on the run

You can do something like this. As in your answer, you would either want to implement this as a singleton, or use a DI framework to inject a single instance wherever you need it: public class ObservableResourceFactory { private ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>(); public ObjectProperty<ResourceBundle> resourcesProperty() { return resources ; } public final ResourceBundle … Read more