2 Ответы Последний ответ: 04.05.2012 10:16, автор: 934068

    Making HtmlEditor ReadOnly


      I am using JavaFx 2.1 and my requirement is to make the editor read-only. I tried disabling it, but if the text is to large the scroll bar is also disabled !
      I have some html tags in the text hence using the HTMLEditor.

        • 1. Re: Making HtmlEditor ReadOnly
          How about something like this with swaps between an editor when in editing mode and view when in viewing mode.
          import javafx.application.Application;
          import javafx.event.ActionEvent;
          import javafx.event.EventHandler;
          import javafx.scene.Scene;
          import javafx.scene.control.ToggleButton;
          import javafx.scene.layout.StackPane;
          import javafx.scene.layout.VBox;
          import javafx.scene.web.HTMLEditor;
          import javafx.scene.web.WebView;
          import javafx.stage.Stage;
          public class ReadOnlyHtmlEditor extends Application {
            public static void main(String[] args) { launch(args); }
            @Override public void start(Stage primaryStage) {
              // create an html editor in which to edit text and a view in which to view it.
              final HTMLEditor editor = new HTMLEditor();
              editor.setHtmlText("<h1>The Gettysburg Address</h1><i>Four score and twenty years ago . . .</i>");
              final WebView view = new WebView();
              // create a stack which swaps back an forth between the html editor and view
              // depending on the state of the editToggleButton.
              final StackPane webStack = new StackPane();
              final ToggleButton editToggleButton = new ToggleButton("Edit");
              editToggleButton.setOnAction(new EventHandler<ActionEvent>() {
                @Override public void handle(ActionEvent arg0) {
                  if (editToggleButton.isSelected()) {
                    webStack.getChildren().addAll(view, editor);
                  } else {
                    webStack.getChildren().addAll(editor, view);
              // set the initial state of the scene to editing.
              // layout the scene.
              final VBox layout = new VBox(10);
              layout.setStyle("-fx-padding: 10; -fx-background-color: cornsilk");
              layout.getChildren().addAll(editToggleButton, webStack);
              primaryStage.setScene(new Scene(layout));
          • 2. Re: Making HtmlEditor ReadOnly