Example usage for javafx.scene.control TextArea appendText

List of usage examples for javafx.scene.control TextArea appendText

Introduction

In this page you can find the example usage for javafx.scene.control TextArea appendText.

Prototype

public void appendText(String text) 

Source Link

Document

Appends a sequence of characters to the content.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    final Label label = new Label("Progress:");
    final ProgressBar progressBar = new ProgressBar(0);
    final ProgressIndicator progressIndicator = new ProgressIndicator(0);

    final Button startButton = new Button("Start");
    final Button cancelButton = new Button("Cancel");
    final TextArea textArea = new TextArea();

    startButton.setOnAction((ActionEvent event) -> {
        startButton.setDisable(true);/*from   ww w. j  a  v  a 2 s . c  o  m*/

        progressBar.setProgress(0);
        progressIndicator.setProgress(0);

        textArea.setText("");
        cancelButton.setDisable(false);

        copyWorker = createWorker(numFiles);

        progressBar.progressProperty().unbind();
        progressBar.progressProperty().bind(copyWorker.progressProperty());
        progressIndicator.progressProperty().unbind();
        progressIndicator.progressProperty().bind(copyWorker.progressProperty());

        copyWorker.messageProperty().addListener(
                (ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                    textArea.appendText(newValue + "\n");
                });

        new Thread(copyWorker).start();
    });

    cancelButton.setOnAction((ActionEvent event) -> {
        startButton.setDisable(false);
        cancelButton.setDisable(true);
        copyWorker.cancel(true);

        progressBar.progressProperty().unbind();
        progressBar.setProgress(0);
        progressIndicator.progressProperty().unbind();
        progressIndicator.setProgress(0);
        textArea.appendText("File transfer was cancelled.");
    });

    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 500, 250, javafx.scene.paint.Color.WHITE);

    FlowPane topPane = new FlowPane(5, 5);
    topPane.setPadding(new Insets(5));
    topPane.setAlignment(Pos.CENTER);
    topPane.getChildren().addAll(label, progressBar, progressIndicator);

    GridPane middlePane = new GridPane();
    middlePane.setPadding(new Insets(5));
    middlePane.setHgap(20);
    middlePane.setVgap(20);
    ColumnConstraints column1 = new ColumnConstraints(300, 400, Double.MAX_VALUE);
    middlePane.getColumnConstraints().addAll(column1);
    middlePane.setAlignment(Pos.CENTER);
    middlePane.add(textArea, 0, 0);

    FlowPane bottomPane = new FlowPane(5, 5);
    bottomPane.setPadding(new Insets(5));
    bottomPane.setAlignment(Pos.CENTER);
    bottomPane.getChildren().addAll(startButton, cancelButton);

    root.setTop(topPane);
    root.setCenter(middlePane);
    root.setBottom(bottomPane);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.virus.removal.javafxapplication.FXMLDocumentController.java

/**
 * @return/*from  w w  w . ja  va  2 s .c o m*/
 */
public TextArea readVirusScanHistoryFromFile() {

    BufferedReader br = null;
    final TextArea textArea = new TextArea();

    try {

        String currentLine;
        final String userWorkingDrive = System.getProperty("user.dir").split(":")[0];

        System.out.println(userWorkingDrive);

        final File file = new File(userWorkingDrive + ":" + File.separator + "VirusScanHistory" + File.separator
                + virusScanHistoryFile);

        System.out.println(file.getParentFile().getAbsolutePath());

        if (file.exists()) {
            br = new BufferedReader(new FileReader(file.getAbsolutePath()));
            while ((currentLine = br.readLine()) != null) {
                if (!currentLine.isEmpty()) {
                    if (StringUtils.contains(currentLine, "PC Name:")) {
                        textArea.appendText(currentLine + "\n\n\n\n");
                    } else {
                        textArea.appendText(currentLine + "\n\n");
                    }
                }
                System.out.println(currentLine);
            }
            System.out.println(textArea.getText());
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    return textArea;
}