fix: #I7UHOH 修复行号宽度不能自动减小的问题;增加默认最小宽度计算
This commit is contained in:
parent
a767c9978d
commit
308fe8db1c
@ -12,16 +12,17 @@ public class LineNumberTextArea extends BorderPane {
|
||||
|
||||
static final int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999,
|
||||
99999999, 999999999, Integer.MAX_VALUE};
|
||||
private static final int MIN_LINE_NUMBER_WIDTH = 30;
|
||||
|
||||
public LineNumberTextArea() {
|
||||
mainTextArea = new TextArea();
|
||||
lineNumberArea = new TextArea();
|
||||
lineNumberArea.setEditable(false);
|
||||
lineNumberArea.setPrefWidth(30);
|
||||
mainTextArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
|
||||
// lineNumberArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
|
||||
// 设置显示滚动条样式类
|
||||
lineNumberArea.setPrefWidth(MIN_LINE_NUMBER_WIDTH);
|
||||
lineNumberArea.setMinWidth(MIN_LINE_NUMBER_WIDTH);
|
||||
// 设定自定义样式
|
||||
lineNumberArea.getStyleClass().add("text-line-number");
|
||||
mainTextArea.getStyleClass().add("main-text-area");
|
||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||
mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberArea());
|
||||
|
||||
@ -49,8 +50,8 @@ public class LineNumberTextArea extends BorderPane {
|
||||
}
|
||||
}
|
||||
//单数字宽度10像素,4为padding=左3+右1
|
||||
int actualWidth = count * 10 + 4;
|
||||
if (actualWidth > lineNumberArea.getWidth()) {
|
||||
int actualWidth = Math.max(count * 10 + 4, MIN_LINE_NUMBER_WIDTH);
|
||||
if (actualWidth != lineNumberArea.getWidth()) {
|
||||
lineNumberArea.setPrefWidth(actualWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,11 +9,19 @@
|
||||
-fx-cursor: text;
|
||||
-fx-padding: 8px 1px 8px 5px;
|
||||
}
|
||||
|
||||
.text-line-number .scroll-bar:vertical {
|
||||
-fx-pref-width: 1;
|
||||
-fx-opacity: 0;
|
||||
}
|
||||
|
||||
.text-line-number .scroll-bar:horizontal {
|
||||
-fx-pref-height: 1;
|
||||
-fx-opacity: 0;
|
||||
}
|
||||
|
||||
/* 主文本框区域样式 */
|
||||
.main-text-area {
|
||||
-fx-border-color: white;
|
||||
-fx-background-color: white;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user