1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package hello; 27 28 import javafx.application.Application; 29 import javafx.scene.Group; 30 import javafx.scene.Scene; 31 import javafx.scene.control.Hyperlink; 32 import javafx.scene.image.Image; 33 import javafx.scene.image.ImageView; 34 import javafx.scene.paint.Color; 35 import javafx.stage.Stage; 36 37 public class HelloHyperlink extends Application { 38 39 private static final String animImageURL = "hello/animated_89_c.gif"; 40 41 public static void main(String[] args) { 42 Application.launch(args); 43 } 44 45 46 @Override public void start(Stage stage) { 47 stage.setTitle("Hello Hyperlink"); 48 Scene scene = new Scene(new Group(), 600, 450); 49 scene.setFill(Color.GHOSTWHITE); 50 51 Hyperlink link = new Hyperlink(); 52 link.setLayoutX(25); 53 link.setLayoutY(40); 54 link.setText("I am a hyperlink!"); 55 ((Group)scene.getRoot()).getChildren().add(link); 56 57 Hyperlink animatedLink = new Hyperlink(); 58 animatedLink.setLayoutX(25); 59 animatedLink.setLayoutY(100); 60 animatedLink.setText("I am a hyperlink with an animated Image!"); 61 animatedLink.setGraphic(imageView(animImageURL, 0, 0, 16, 16)); 62 ((Group)scene.getRoot()).getChildren().add(animatedLink); 63 64 stage.setScene(scene); 65 stage.show(); 66 } 67 68 private static ImageView imageView(String url, int x, int y, int w, int h) { 69 ImageView imageView = new ImageView(); 70 imageView.setX(x); 71 imageView.setY(y); 72 imageView.setFitWidth(w); 73 imageView.setFitHeight(h); 74 imageView.setPreserveRatio(true); 75 imageView.setImage(new Image(url)); 76 return imageView; 77 } 78 }