forked from TheCyaniteProject/exit_code_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoTextArea.java
More file actions
111 lines (82 loc) · 3.79 KB
/
Copy pathAutoTextArea.java
File metadata and controls
111 lines (82 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package exitcode;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
public class AutoTextArea extends StackPane {
private Label autoLabel;
private TextArea autoTextArea;
public AutoTextArea(String text) {
this.autoLabel = new Label(text);
this.autoTextArea = new TextArea(text);
this.autoLabel.setWrapText(true);
this.autoTextArea.setWrapText(true);
this.autoTextArea.setEditable(false);
this.autoLabel.setStyle("-fx-text-fill: transparent;");
this.autoLabel.setPadding(new Insets(0, 10, 0, 11)); //Top, Right, Bottom, Left
this.autoTextArea.setPadding(new Insets(2, 0, 0, 0)); //Top, Right, Bottom, Left
this.autoLabel.prefWidthProperty().bind(this.widthProperty());
this.autoTextArea.prefWidthProperty().bind(this.autoLabel.widthProperty().add(14));
this.autoTextArea.prefHeightProperty().bind(this.autoLabel.heightProperty().add(16));
this.getChildren().addAll(this.autoLabel, this.autoTextArea);
this.autoLabel.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue) {
updateFromLabel();
}
});
}
public AutoTextArea() {
this.autoLabel = new Label();
this.autoTextArea = new TextArea();
this.autoLabel.setWrapText(true);
this.autoTextArea.setWrapText(true);
this.autoTextArea.setEditable(false);
this.autoLabel.setStyle("-fx-text-fill: transparent;");
this.autoLabel.setPadding(new Insets(0, 10, 0, 11)); //Top, Right, Bottom, Left
this.autoTextArea.setPadding(new Insets(2, 0, 0, 0)); //Top, Right, Bottom, Left
this.autoLabel.prefWidthProperty().bind(this.widthProperty());
this.autoTextArea.prefWidthProperty().bind(this.autoLabel.widthProperty().add(14));
this.autoTextArea.prefHeightProperty().bind(this.autoLabel.heightProperty().add(16));
this.getChildren().addAll(this.autoLabel, this.autoTextArea);
this.autoLabel.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue) {
updateFromLabel();
}
});
}
private void updateFromLabel() {
this.autoTextArea.setText(this.autoLabel.getText());
}
public Label getLabel() {
return this.autoLabel;
}
public void setFont(Font value) {
this.autoLabel.setFont(value);
this.autoTextArea.setFont(value);
}
public Label get() {
return getLabel();
}
public TextArea getTextArea() {
return this.autoTextArea;
}
public void clear() {
//this.autoTextArea.clear();
this.autoLabel.setText("");
}
public void setText(String text) {
//this.autoTextArea.setText(text);
this.autoLabel.setText(text);
}
public void appendText(String text) {
this.setText(this.getText() + text);
}
public String getText() {
return this.autoLabel.getText();
}
}