/** * Copyright (c) 2008, 2012 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. */ import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.Node; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.scene.web.HTMLEditor; /** * A sample that demonstrates the HTML Editor. You can make changes to the * example text, and the resulting generated HTML is displayed. * * @related controls/text/SimpleLabel * @see javafx.scene.web.HTMLEditor */ public class HTMLEditorSample extends Application { private HTMLEditor htmlEditor = null; private final String INITIAL_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." +"Nam tortor felis, pulvinar in scelerisque cursus, pulvinar at ante. Nulla consequat " + "congue lectus in sodales. Nullam eu est a felis ornare bibendum et nec tellus. " + "Vivamus non metus tempus augue auctor ornare. Duis pulvinar justo ac purus adipiscing " + "pulvinar. Integer congue faucibus dapibus. Integer id nisl ut elit aliquam sagittis " + "gravida eu dolor. Etiam sit amet ipsum sem."; private void init(Stage primaryStage) { Group root = new Group(); primaryStage.setScene(new Scene(root)); VBox vRoot = new VBox(); vRoot.setPadding(new Insets(8, 8, 8, 8)); vRoot.setSpacing(5); htmlEditor = new HTMLEditor(); htmlEditor.setPrefSize(500, 245); htmlEditor.setHtmlText(INITIAL_TEXT); vRoot.getChildren().add(htmlEditor); final Label htmlLabel = new Label(); htmlLabel.setMaxWidth(500); htmlLabel.setWrapText(true); ScrollPane scrollPane = new ScrollPane(); scrollPane.getStyleClass().add("noborder-scroll-pane"); scrollPane.setContent(htmlLabel); scrollPane.setFitToWidth(true); scrollPane.setPrefHeight(180); Button showHTMLButton = new Button("Show the HTML below"); vRoot.setAlignment(Pos.CENTER); showHTMLButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { htmlLabel.setText(htmlEditor.getHtmlText()); } }); vRoot.getChildren().addAll(showHTMLButton, scrollPane); root.getChildren().addAll(vRoot); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); } public static void main(String[] args) { launch(args); } }