java - 如何在 javafx 中隐藏组合框上的向下箭头按钮?

标签 java javafx-2

我有一个可编辑的 ComboBox,我希望“隐藏”向下箭头按钮,使其看起来像一个普通的文本框。

最佳答案

使用 css 作为,

.combo-box .arrow, .combo-box .arrow-button{
    -fx-background-color: transparent;
}

示例代码::

public class ComboboxSample extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    final Button button = new Button("Send");
    final Label notification = new Label();
    final TextField subject = new TextField("");
    final TextArea text = new TextArea("");

    String address = " ";

    @Override
    public void start(Stage stage) {
        stage.setTitle("ComboBoxSample");
        Scene scene = new Scene(new Group(), 450, 250);
// Load the css as below to the scene
        scene.getStylesheets()
                .add(ComboboxSample.class.getResource("styles.css").toExternalForm());

        final ComboBox emailComboBox = new ComboBox();
        emailComboBox.setEditable(true);
        emailComboBox.getItems().addAll("jacob.smith@example.com",
                "isabella.johnson@example.com", "ethan.williams@example.com",
                "emma.jones@example.com", "michael.brown@example.com");

        final ComboBox priorityComboBox = new ComboBox();
        priorityComboBox.getItems().addAll("Highest", "High", "Normal", "Low",
                "Lowest");

        priorityComboBox.setValue("Normal");

        GridPane grid = new GridPane();
        grid.setVgap(4);
        grid.setHgap(10);
        grid.setPadding(new Insets(5, 5, 5, 5));
        grid.add(new Label("To: "), 0, 0);
        grid.add(emailComboBox, 1, 0);
        grid.add(new Label("Priority: "), 2, 0);
        grid.add(priorityComboBox, 3, 0);
        grid.add(new Label("Subject: "), 0, 1);
        grid.add(subject, 1, 1, 3, 1);
        grid.add(text, 0, 2, 4, 1);
        grid.add(button, 0, 3);
        grid.add(notification, 1, 3, 3, 1);

        Group root = (Group) scene.getRoot();
        root.getChildren().add(grid);
        stage.setScene(scene);
        stage.show();
    }
}

输出:

enter image description here

关于java - 如何在 javafx 中隐藏组合框上的向下箭头按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21379865/

相关文章:

java - 无法让我的 while 语句正常工作

java - @Inheritance默认为SINGLE_TABLE,还是默认为 "fallthrough"或SINGLE_TABLE?

java - jxls - 使用动态图像创建 Excel 文件

mysql - 如何从 ComboBox 返回对象

java - 如何在 JavaFX 中创建具有透明背景的启动画面

没有实现的java接口(interface)

java - 如何在我的服务器上使用 Lucene

java - 使用 Commons-compression 在 Java 中读取 tar.gz

javafx - 如何在调整 ScrollPane 大小时显示滚动条? (在 JavaFX 中)

java - 为什么 StringProperty[值 : ""] is displayed in my table