Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

open external hostservices url in javafx

import java.io.File;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class OpenResourceNatively extends Application {

    @Override
    public void start(Stage primaryStage) {
        TextField textField = new TextField("http://stackoverflow.com/questions/39898704");
        Button openURLButton = new Button("Open URL");
        EventHandler<ActionEvent> handler = e -> open(textField.getText());
        textField.setOnAction(handler);
        openURLButton.setOnAction(handler);

        FileChooser fileChooser = new FileChooser();
        Button openFileButton = new Button("Open File...");
        openFileButton.setOnAction(e -> {
            File file = fileChooser.showOpenDialog(primaryStage);
            if (file != null) {
                open(file.toURI().toString());
            }
        });

        VBox root = new VBox(5, 
                new HBox(new Label("URL:"), textField, openURLButton),
                new HBox(openFileButton)
        );

        root.setPadding(new Insets(20));
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    private void open(String resource) {
        getHostServices().showDocument(resource);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: array erstellen java 
Java :: square operator java 
Java :: how to check if parsing in integer is possible in java 
Java :: maximum occuring element in java 
Java :: how to increase a variable once java 
Java :: what is void in java 
Java :: intellij disable welcome screen 
Java :: short array in java 
Java :: setCookie("showPopupBannerBeta", 1, 1 
Java :: struct in java 
Java :: convert text file into binnary format bitmap using java 
Java :: java swing place objects vertically 
Java :: rgb code from java color 
Java :: priorityQueue peek java 
Java :: default constructor java 
Java :: odd numbers in java 
Java :: The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program. 
Java :: date data type in java 
Java :: @entity annotation in spring boot 
Java :: Java getClass() method 
Java :: xml button color not changing 
Java :: java coding standards for classes 
Java :: input 3 int 1 line in java 
Java :: round off and round up 
Java :: android studio fecth audio from app directory 
Sql :: sql server reset identity 
Sql :: oracle get table schema 
Sql :: oracle sql limit results 
Sql :: postgresql blocked on mac 
Sql :: list tables sqlite 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =