Skip to content

Instantly share code, notes, and snippets.

@skrb
Created August 29, 2013 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skrb/6384723 to your computer and use it in GitHub Desktop.
Save skrb/6384723 to your computer and use it in GitHub Desktop.
Hyperlink Demo
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Test extends Application {
@Override
public void start(Stage stage) {
BorderPane root = new BorderPane();
WebView view = new WebView();
root.setCenter(view);
final WebEngine engine = view.getEngine();
FlowPane flow = new FlowPane();
flow.setAlignment(Pos.CENTER);
root.setTop(flow);
Label label1 = new Label("This is link to");
Hyperlink link = new Hyperlink("http://google.co.jp/");
Label label2 = new Label(" Please click the LINK.");
flow.getChildren().addAll(label1, link, label2);
link.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
engine.load("http://google.co.jp/");
}
});
Scene scene = new Scene(root, 600, 800);
stage.setScene(scene);
stage.show();
}
public static void main(String... args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment