/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworld; import javafx.application.Application; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Popup; import javafx.stage.Stage; /** * * @author paru */ public class PopupLabelBug extends Application { private static double WIDTH = 400; private static double HEIGHT = 400; @Override public void start(Stage stage) { stage.setTitle("Popup Label Bug"); stage.setWidth(WIDTH); stage.setHeight(HEIGHT); stage.setScene(new Scene(createScene(stage))); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } private static Group createScene(final Stage stage) { Group rootGroup = new Group(); ObservableList content = rootGroup.getChildren(); Rectangle rect = new Rectangle(); rect.setX(0); rect.setY(0); rect.setWidth(WIDTH); rect.setHeight(HEIGHT); rect.setFill(Color.CYAN); rect.setStroke(Color.RED); rect.setStrokeWidth(2); content.add(rect); final Button showButton = new Button("Popup"); showButton.setLayoutX(50); showButton.setLayoutY(50); showButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { Popup popup = new Popup(); Rectangle rect = new Rectangle(); rect.setX(0); rect.setY(0); rect.setWidth(WIDTH); rect.setHeight(HEIGHT); rect.setFill(Color.PINK); rect.setStroke(Color.RED); rect.setStrokeWidth(2); Label label = new Label(); ImageView imageview = new ImageView(); imageview.setFitWidth(20.0); imageview.setFitHeight(20.0); imageview.setImage(new Image("file:src/helloworld/duke.gif")); label.setText("I am a Label with Graphic!"); label.setGraphic(imageview); label.setLayoutX(50); label.setLayoutY(100); label.setStyle("-fx-border-color: black;"); popup.getContent().addAll(rect, label); popup.setAutoHide(true); popup.show(showButton, stage.getX()+500, stage.getY()+100); } }); content.add(showButton); final TextField textbox = new TextField(); textbox.setLayoutX(50); textbox.setLayoutY(100); content.add(textbox); Label label = new Label(); ImageView imageview = new ImageView(); imageview.setFitWidth(20.0); imageview.setFitHeight(20.0); imageview.setImage(new Image("file:src/helloworld/duke.gif")); label.setText("I am a Label with Graphic!"); label.setGraphic(imageview); label.setLayoutX(50); label.setLayoutY(200); label.setStyle("-fx-border-color: black;"); content.add(label); return rootGroup; } }