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,
|
static final int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999,
|
||||||
99999999, 999999999, Integer.MAX_VALUE};
|
99999999, 999999999, Integer.MAX_VALUE};
|
||||||
|
private static final int MIN_LINE_NUMBER_WIDTH = 30;
|
||||||
|
|
||||||
public LineNumberTextArea() {
|
public LineNumberTextArea() {
|
||||||
mainTextArea = new TextArea();
|
mainTextArea = new TextArea();
|
||||||
lineNumberArea = new TextArea();
|
lineNumberArea = new TextArea();
|
||||||
lineNumberArea.setEditable(false);
|
lineNumberArea.setEditable(false);
|
||||||
lineNumberArea.setPrefWidth(30);
|
lineNumberArea.setPrefWidth(MIN_LINE_NUMBER_WIDTH);
|
||||||
mainTextArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
|
lineNumberArea.setMinWidth(MIN_LINE_NUMBER_WIDTH);
|
||||||
// lineNumberArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
|
// 设定自定义样式
|
||||||
// 设置显示滚动条样式类
|
|
||||||
lineNumberArea.getStyleClass().add("text-line-number");
|
lineNumberArea.getStyleClass().add("text-line-number");
|
||||||
|
mainTextArea.getStyleClass().add("main-text-area");
|
||||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||||
mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberArea());
|
mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberArea());
|
||||||
|
|
||||||
@ -49,8 +50,8 @@ public class LineNumberTextArea extends BorderPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//单数字宽度10像素,4为padding=左3+右1
|
//单数字宽度10像素,4为padding=左3+右1
|
||||||
int actualWidth = count * 10 + 4;
|
int actualWidth = Math.max(count * 10 + 4, MIN_LINE_NUMBER_WIDTH);
|
||||||
if (actualWidth > lineNumberArea.getWidth()) {
|
if (actualWidth != lineNumberArea.getWidth()) {
|
||||||
lineNumberArea.setPrefWidth(actualWidth);
|
lineNumberArea.setPrefWidth(actualWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,15 +5,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 不显示滚动条 */
|
/* 不显示滚动条 */
|
||||||
.text-line-number .content{
|
.text-line-number .content {
|
||||||
-fx-cursor: text;
|
-fx-cursor: text;
|
||||||
-fx-padding: 8px 1px 8px 5px;
|
-fx-padding: 8px 1px 8px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-line-number .scroll-bar:vertical {
|
.text-line-number .scroll-bar:vertical {
|
||||||
-fx-pref-width: 1;
|
-fx-pref-width: 1;
|
||||||
-fx-opacity: 0;
|
-fx-opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-line-number .scroll-bar:horizontal {
|
.text-line-number .scroll-bar:horizontal {
|
||||||
-fx-pref-height: 1;
|
-fx-pref-height: 1;
|
||||||
-fx-opacity: 0;
|
-fx-opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 主文本框区域样式 */
|
||||||
|
.main-text-area {
|
||||||
|
-fx-border-color: white;
|
||||||
|
-fx-background-color: white;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user