Skip to content
This repository was archived by the owner on Mar 26, 2019. It is now read-only.

Commit bec396f

Browse files
committed
使用css控制显示效果,添加自定义字体(但是没效果)
1 parent e25139e commit bec396f

File tree

6 files changed

+298
-136
lines changed

6 files changed

+298
-136
lines changed

.idea/cssdialects.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 247 additions & 125 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/me/ryan/MainApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public void start(Stage primaryStage) {
3333
// 4. 将 textView 和 scoresView 添加进RootView
3434
root.getChildren().addAll(textView, scoresView);
3535

36-
// 5. 创建包含了 RootView 的 Scene,添加样式表,并将其放入 PrimaryStage。
36+
// 5. 创建包含了 RootView 的 Scene
3737
Scene scene = new Scene(root);
38-
scene.getStylesheets().add("/css/root.css");
3938

4039
primaryStage.setScene(scene);
40+
primaryStage.setTitle("跟打器");
4141

4242
// 6. 显示primaryStage
4343
primaryStage.show();

src/main/java/me/ryan/controller/TextController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import javafx.scene.input.KeyEvent;
1111
import javafx.scene.paint.Color;
1212
import javafx.scene.paint.Paint;
13-
import javafx.scene.text.Font;
1413
import javafx.scene.text.Text;
1514
import javafx.scene.text.TextFlow;
1615
import javafx.util.Duration;
@@ -94,7 +93,6 @@ public void setTextShow(String text) {
9493
text.codePoints().forEach(
9594
c -> {
9695
var text1 = new Text(new String(Character.toChars(c)));
97-
text1.setFont(Font.font("Verdana", 20));
9896
textShowArea.getChildren().add(text1);
9997
}
10098
);

src/main/resources/css/root.css

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1+
@font-face {
2+
font-family: SourceHanSerifCN-Regular;
3+
src: url("/font/SourceHanSerifCN-Regular.otf");
4+
}
15

2-
-fx-background-color {
6+
/*1. 全局配置*/
7+
.root {
8+
-fx-font-family: "SourceHanSerifCN-Regular";
9+
-fx-font-size: 14;
10+
/*-fx-background: ;*/
11+
-fx-text-alignment: center;
12+
}
313

14+
/*2. 菜单栏*/
15+
MenuBar {
16+
}
17+
18+
Menu {
19+
20+
}
21+
22+
/*3. 跟打显示栏*/
23+
TextFlow {
24+
}
25+
26+
TextFlow > Text {
27+
/*text 没有背景色属性*/
28+
/*-fx-text-fill: ;*/
29+
}
30+
31+
/*4. 跟打输入栏*/
32+
TextArea {
33+
}
34+
35+
/*5. 成绩显示栏*/
36+
TableView {
37+
}
38+
39+
.table-column {
440
}

src/main/resources/view/RootView.fxml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
<?import javafx.scene.control.*?>
44
<?import javafx.scene.layout.VBox?>
5-
<VBox xmlns:fx="http://javafx.com/fxml/1"
6-
fx:controller="me.ryan.controller.RootController"
7-
maxHeight="Infinity" maxWidth="Infinity"
5+
<VBox maxHeight="Infinity" maxWidth="Infinity"
86
minHeight="440" minWidth="800"
97
prefHeight="440.0" prefWidth="800.0"
10-
xmlns="http://javafx.com/javafx/8.0.141">
8+
stylesheets="@/css/root.css"
9+
xmlns="http://javafx.com/javafx/8.0.141"
10+
xmlns:fx="http://javafx.com/fxml/1"
11+
fx:controller="me.ryan.controller.RootController">
1112

1213
<children>
1314
<MenuBar>
1415
<menus>
1516
<Menu mnemonicParsing="false" text="发文">
1617
<items>
1718
<MenuItem mnemonicParsing="false" text="打开载文面板"/>
18-
<MenuItem mnemonicParsing="false" text="QQ剪切版载文"
19-
onAction="#setTextFromCupboard"/>
19+
<MenuItem mnemonicParsing="false" onAction="#setTextFromCupboard" text="QQ剪切版载文"/>
2020
</items>
2121
</Menu>
2222
<Menu mnemonicParsing="false" text="模式">

0 commit comments

Comments
 (0)