Textarea javaFx颜色 [英] Textarea javaFx Color
问题描述
我正在尝试开发一个看起来像终端控制台的应用程序,我正在使用TextArea,我的愿望是黑色背景和绿色文字,
我想在不使用任何ccs模板的情况下这样做
我知道我的问题在这里看起来像是重复的:
推荐的方法是使用外部CSS文件,如您链接的示例中所示。
如果由于某种原因您不想这样做,请尝试
style = - fx-control-inner-background:#000000; -fx-font-family:Consolas; -fx-highlight-fill:#00ff00; -fx-highlight-text-fill:#000000; -fx-text-fill:#00ff00; FXML文件中的
,或等效地
terminalTextArea.setStyle( - fx-control-inner-background:#000000; -fx-font-family:Consolas; -fx-highlight-fill:#00ff00; -fx- highlight-text-fill:#000000; -fx-text-fill:#00ff00;);
在您的控制器的初始化()
方法。
SSCCE:
StyledTextArea.fxml:
<?xml version =1.0encoding = UTF-8?>
<?import javafx.scene.layout.HBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.text.Font?>
< HBox xmlns:fx =http: //javafx.com/fxml/1>
< padding>
< Insets top =12left =12right =12bottom =12/>
< / padding>
< TextArea
prefHeight =64.0
prefWidth = 402.0
style = - fx-control-inner-background:#000000; -fx-font-family:Consolas; -fx-highlight-fill:#00ff00; -fx-highlight-text-fill:#000000; -fx-text-fill:#00ff00;
text =终端>
< font>
<字体名称=系统粗体尺寸=14.0/>
< ; / font>
< / TextArea>
< / HBox>
和测试类:
import java.io.IOException;
import javafx.application。应用程序;
导入javafx.fxml.FXMLLoader;
导入javafx.scene.Scene;
导入javafx.stage.Stage;
公共类StyledTextArea扩展Application {
@Override
public void start(Stage primaryStage)抛出IOException {
primaryStage.setScene(new Scene(
FXMLLoader.load(getClass()。getResource(StyledTextArea) .fxml))
));
primaryStage.show();
}
public static void main(String [] args){
启动(args);
}
}
Am trying to develop an app that looks like a terminal console, am using a TextArea for that and my wish is to habe a black background and green text,
the point i want to do this without using any ccs template
I know that my question can look like a duplicated in here:
javafx textarea background color not css
or
JavaFX CSS styling of TextArea does not work
but after reading those and trying what they suggested I found no luck to solve my issue
What I tried so far:
in the FXML:
<TextArea
fx:id="terminalTextArea"
layoutX="14.0"
layoutY="85.0"
prefHeight="64.0"
prefWidth="402.0"
style="-fx-font-family: Consolas; -fx-highlight-fill: #00ff00; -fx-highlight-text-fill: #000000; -fx-text-fill: #00ff00; -fx-background-color:#000000;"
text="Terminal"
AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</TextArea>
but no luck ....
and in the source-code:
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println("init here");
terminalTextArea.setStyle("-fx-text-fill: black;");
}
the only thing that I get is a bordered color like in the image below....
does any one of you had the same problem before????
Tnxs in advance
The recommended way is to use an external CSS file, as in the examples you linked.
If for some reason you don't want to do that, try
style="-fx-control-inner-background:#000000; -fx-font-family: Consolas; -fx-highlight-fill: #00ff00; -fx-highlight-text-fill: #000000; -fx-text-fill: #00ff00; "
in your FXML file, or equivalently
terminalTextArea.setStyle("-fx-control-inner-background:#000000; -fx-font-family: Consolas; -fx-highlight-fill: #00ff00; -fx-highlight-text-fill: #000000; -fx-text-fill: #00ff00; ");
in your controller's initialize()
method.
SSCCE:
StyledTextArea.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.text.Font?>
<HBox xmlns:fx="http://javafx.com/fxml/1" >
<padding>
<Insets top="12" left="12" right="12" bottom="12"/>
</padding>
<TextArea
prefHeight="64.0"
prefWidth="402.0"
style="-fx-control-inner-background:#000000; -fx-font-family: Consolas; -fx-highlight-fill: #00ff00; -fx-highlight-text-fill: #000000; -fx-text-fill: #00ff00; "
text="Terminal">
<font>
<Font name="System Bold" size="14.0" />
</font>
</TextArea>
</HBox>
and a test class:
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class StyledTextArea extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
primaryStage.setScene(new Scene(
FXMLLoader.load(getClass().getResource("StyledTextArea.fxml"))
));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这篇关于Textarea javaFx颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!