为什么禁用JavaFX TextArea具有与TextField不同的颜色 [英] Why does disabled JavaFX TextArea has a different color than TextField

查看:2703
本文介绍了为什么禁用JavaFX TextArea具有与TextField不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新编写一个JavaFX应用程序,但我有一个问题与:disabled 样式。当我尝试更改 -fx-text-fill -fx-opacity设置时,textareas仍然会稍微比文本字段更浅的文本颜色。这是我现在的样式:

  / ***文本字段和区域*** / 
。 text-field,
.text-area {
-fx-text-fill:#000;
-fx-opacity:1.0;
}

.text-field:disabled,
.text-area:disabled {
-fx-text-fill:#000;
-fx-opacity:0.5;
}

这是禁用的组件在程序中的显示方式:
< a href =http://i.stack.imgur.com/RAZXf.png =nofollow> JavaFX应用程序的屏幕截图



正如你所看到的, TextField 的文本颜色是#7a7a7a ,它是#000 。然而 TextArea 看起来具有#c7c7c7 的颜色,这是#000



有没有人知道如何获得textareas和textfields一样的禁用颜色?

解决方案

发生了什么



IMO目前的行为是一个错误,在



输出(应用CSS工作环境) p>


I am restyling a JavaFX application, but I have a problem with the :disabled styles. When I try to change the -fx-text-fill and -fx-opacity settings, textareas still get a slightly lighter text color than textfields. This is the style I got right now:

/*** Text Fields and Areas ***/
.text-field,
.text-area {
    -fx-text-fill: #000;
    -fx-opacity: 1.0;
}

.text-field:disabled,
.text-area:disabled {
    -fx-text-fill: #000;
    -fx-opacity: 0.5;
}

This is how the disabled components look in the program: Screenshot from the JavaFX application

As you can see, the text color of the TextField is #7a7a7a which is 50% of #000. The TextArea however appear to have the color #c7c7c7 which is 25% of #000.

Does anyone know how I can get the same disabled color for textareas as for textfields?

解决方案

What's going on

IMO the current behaviour is a bug and should be filed at http://bugreport.java.com (I have done this, unfortunately the Java bug reporting system does not provide any way to track this bug report unless it is accepted by the JavaFX team).

The issue is that the opacity modifier for the text in the text area is applied twice. The default TextArea skin is implemented as a TextArea control node, with an internal ScrollPane in it and, when the TextArea is disabled, the opacity of both is set to 0.4, so the text (and scroll bars in the scroll pane) have the disability opacity fading effect applied twice (which is wrong). You can see this by inspecting a disabled TextArea control in ScenicView.

Workaround

Explicitly set the disabled scroll-pane's opacity to 1 when it is contained within a text-input control.

.text-input > .scroll-pane:disabled {
    -fx-opacity: 1;
}

Sample app:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.scenicview.ScenicView;

public class DisabilityAssistance extends Application {

    @Override
    public void start(Stage stage) throws Exception{
        TextArea area = new TextArea("Text Area");
        area.setDisable(true);
        TextField field = new TextField("Text Field");
        field.setDisable(true);

        Scene scene = new Scene(new VBox(10, area, field));
        stage.setScene(scene);
        stage.show();

        scene.getStylesheets().add(getClass().getResource(
                "disability.css"
        ).toURI().toURL().toExternalForm());

        ScenicView.show(stage.getScene());
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Output (without CSS work-around applied):

Output (with CSS work-around applied):

这篇关于为什么禁用JavaFX TextArea具有与TextField不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆