шпаргалки
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

2 years ago
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxpaneexample;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.*;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
/**
*
* @author denis
*/
public class TextAreaExample extends Stage{
public void init(){
TextField field = new TextField();
TextArea area = new TextArea();
Button append = new Button("Append");
Button clear = new Button("Clear");
append.setOnAction(e -> {
area.appendText(field.getText() + "\n");
field.clear();
});
field.setOnKeyPressed(e -> {
if(e.getCode().equals(KeyCode.ENTER)){
area.appendText(field.getText() + "\n");
field.clear();
}
});
clear.setOnAction(e -> {
area.clear();
field.clear();
});
GridPane root = new GridPane();
root.add(field, 0, 0, 100, 1);
root.add(area, 0, 2, 100, 10);
HBox hBox = new HBox(10, append, clear);
hBox.setAlignment(Pos.CENTER);
root.add(hBox, 30, 13, 100, 1);
Scene scene = new Scene(root, 300, 250);
setTitle("TextAreaExample");
setScene(scene);
show();
}
}