1

I am taking my first step with JavaFx, using InteliJ for debugging and construction of the scene.

I have added a button that is supposed to open the standard web browser.

To check the link between the button and the controller, I have added a print command that works ok, printing "Hello" to the console. But the code to open the browser does not execute and makes the window freeze.

The code snippets works great form a separate file, but I can't get it working from the controller.

UPDATE: with the from the colleagues I've got it working. The complete code is below.

// working code

package sample;


import com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory;
import com.sun.javafx.application.HostServicesDelegate;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.stage.Stage;

public class Controller extends Application {

    public void openBrowser(ActionEvent actionEvent) throws Exception {

        HostServicesDelegate hostServices = HostServicesFactory.getInstance(this);
        getHostServices().showDocument("http://www.yahoo.com");

    }

    @Override
    public void start(Stage primaryStage) throws Exception {

    }
}
rainer
  • 3,295
  • 5
  • 34
  • 50

0 Answers0