Java Reference
In-Depth Information
Listing 6-13. The createHtmlEditorDemoNode() Method Located in StarterAppMain.java
Node createHtmlEditorDemoNode() {
final BorderPane htmlEditorDemo;
final HTMLEditor htmlEditor = new HTMLEditor();
htmlEditor.setHtmlText("<p>Replace this text</p>");
Button viewHtmlButton = new Button("View HTML");
viewHtmlButton.setOnAction(e -> {
Popup alertPopup = createAlertPopup(htmlEditor.getHtmlText());
alertPopup.show(stage,
(stage.getWidth() - alertPopup.getWidth()) / 2 + stage.getX(),
(stage.getHeight() - alertPopup.getHeight()) / 2 + stage.getY());
});
htmlEditorDemo = new BorderPane();
htmlEditorDemo.setCenter(htmlEditor);
htmlEditorDemo.setBottom(viewHtmlButton);
BorderPane.setAlignment(viewHtmlButton, Pos.CENTER);
BorderPane.setMargin(viewHtmlButton, new Insets(10, 0, 10, 0));
return htmlEditorDemo;
}
Creating a Popup
As you experienced in Step 33 in the exercise, when the Button is clicked, the Popup shown in Figure 6-13 is created
and displayed. This Popup displays the HTML that represents the text in the editing area. The preceding snippet
contains the code that calls the show() method of the Popup . The Popup , however, is created by another method in
StarterAppMain.java , arbitrarily named createAlertPopup() and shown in Listing 6-14.
Listing 6-14. The createAlertPopup () Method Located in StarterAppMain.java
Popup createAlertPopup(String text) {
Popup alertPopup = new Popup();
htmlLabel = new Label(text);
htmlLabel.setWrapText(true);
htmlLabel.setMaxWidth(280);
htmlLabel.setMaxHeight(140);
Button okButton = new Button("OK");
okButton.setOnAction(e -> alertPopup.hide());
BorderPane borderPane = new BorderPane();
borderPane.setCenter(htmlLabel);
borderPane.setBottom(okButton);
Rectangle rectangle = new Rectangle(300, 200, Color.LIGHTBLUE);
rectangle.setArcHeight(20);
rectangle.setArcWidth(20);
rectangle.setStroke(Color.GRAY);
rectangle.setStrokeWidth(2);
StackPane contentPane = new StackPane(rectangle, borderPane);
 
Search WWH ::




Custom Search