From 308fe8db1cb9d8f2c02d78f7e9bdc5c3fe29efa7 Mon Sep 17 00:00:00 2001 From: songdragon Date: Sun, 20 Aug 2023 21:57:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20#I7UHOH=20=E4=BF=AE=E5=A4=8D=E8=A1=8C?= =?UTF-8?q?=E5=8F=B7=E5=AE=BD=E5=BA=A6=E4=B8=8D=E8=83=BD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=87=8F=E5=B0=8F=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E6=9C=80=E5=B0=8F=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/jnotepad/ui/LineNumberTextArea.java | 13 +++++++------ src/main/resources/css/styles.css | 10 +++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jcnc/jnotepad/ui/LineNumberTextArea.java b/src/main/java/org/jcnc/jnotepad/ui/LineNumberTextArea.java index 5bb431d..1391df0 100644 --- a/src/main/java/org/jcnc/jnotepad/ui/LineNumberTextArea.java +++ b/src/main/java/org/jcnc/jnotepad/ui/LineNumberTextArea.java @@ -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); } } diff --git a/src/main/resources/css/styles.css b/src/main/resources/css/styles.css index 42b923b..695b475 100644 --- a/src/main/resources/css/styles.css +++ b/src/main/resources/css/styles.css @@ -5,15 +5,23 @@ } /* 不显示滚动条 */ -.text-line-number .content{ +.text-line-number .content { -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; } \ No newline at end of file -- Gitee