From fb36eadfb9278924eec8ad108c085f2e4fc678fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E8=BD=B2?= Date: Thu, 4 May 2023 22:00:04 +0800 Subject: [PATCH] =?UTF-8?q?-=E6=B7=BB=E5=8A=A0=E5=8F=A6=E5=AD=98=E4=B8=BA?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=90=8D=E7=A7=B0=EF=BC=8C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=20-=E5=9C=A8=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E4=B8=80=E4=B8=AA=E7=A9=BA=E7=99=BD=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 1 - src/main/java/JNotepad.java | 11 ++++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 37f7485..e8fe5af 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,7 +6,6 @@ - diff --git a/src/main/java/JNotepad.java b/src/main/java/JNotepad.java index 1dacc5e..0c2c057 100644 --- a/src/main/java/JNotepad.java +++ b/src/main/java/JNotepad.java @@ -64,6 +64,13 @@ public class JNotepad extends Application { root.setBottom(statusLabel); BorderPane.setMargin(statusLabel, new Insets(5, 10, 5, 10)); + TextArea textArea = new TextArea(); // 创建新的文本编辑区 + Tab tab = new Tab("新建文件 " + ++tabIndex); // 创建新的Tab页 + tab.setContent(textArea); + tabPane.getTabs().add(tab); + tabPane.getSelectionModel().select(tab); + updateStatusLabel(textArea); + // 创建场景并设置主界面 Scene scene = new Scene(root, 800, 600); primaryStage.setScene(scene); @@ -76,7 +83,7 @@ public class JNotepad extends Application { @Override public void handle(ActionEvent event) { TextArea textArea = new TextArea(); // 创建新的文本编辑区 - Tab tab = new Tab("新建文件 " + ++tabIndex); // 创建新的Tab页 + Tab tab = new Tab("新建文本 " + ++tabIndex); // 创建新的Tab页 tab.setContent(textArea); tabPane.getTabs().add(tab); tabPane.getSelectionModel().select(tab); @@ -154,6 +161,8 @@ public class JNotepad extends Application { Tab selectedTab = tabPane.getSelectionModel().getSelectedItem(); if (selectedTab != null) { FileChooser fileChooser = new FileChooser(); + fileChooser.setInitialFileName("新建文本"); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("文本文档", "*.txt")); File file = fileChooser.showSaveDialog(null); if (file != null) { try {