0

I have a user interface, with buttons, textfields and comboboxes. It depends on the user connection to make them editable or not. With Fields it's easy, just :

setEditable(false);

But comboBox is a problem for me.

When I use:

setDisabled(true);
setOpacity(1.0);

The combobox is fully visible, not editable (editable in a comboBox means that you write your own text, it's automatically set to false), but the text in the combobox is grey.

Do you have an idea on how to make it not editable, and make it look like an editableComboBox. The text shall still be visible.

4

2 回答 2

1

如果我对您的理解正确,您希望 ComboBox 不可编辑,但仍然看起来像可编辑时的通常样子。如果是这样,您可以使用 JavaFX 中的 CSS 来修改控件的外观。

对于 ComboBox,它在内部使用一个 TextField,它也继承了 TextInputControl 的 CSS,因此您可以修改文本的颜色和其他外观,如 JavaFX CSS 参考中所述:

-fx-text-fill: black;

来源:http ://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#textinputcontrol

更新:

我能够建立一个使用 CSS 将背景颜色设置为与可编辑组合框相同的小示例应用程序:

package cssstyling;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class CssStyling extends Application {

    @Override
    public void start(Stage primaryStage) {
        Group root = new Group();
        Scene scene = new Scene(root, 500, 500, Color.BLACK);

        ComboBox b = new ComboBox();
        b.setButtonCell(new ListCell());
        b.getButtonCell().setStyle("-fx-background-color: white;");
        b.setLayoutX(220);
        b.setLayoutY(20);
        root.getChildren().add(b);

        primaryStage.setTitle("JavaFX Scene Graph Demo");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

希望它有用!

于 2013-05-29T13:25:20.273 回答
0

CSS 文档描述了节点可能具有的伪类。这包括 .disabled 伪类。因此,您应该在其 .dusabled 伪类中为禁用控件提供所需的文本填充。

于 2013-05-29T14:23:39.293 回答