如何在javafx中隐藏组合框上的向下箭头按钮? [英] How to hide the down arrow button on a combobox in javafx?

查看:548
本文介绍了如何在javafx中隐藏组合框上的向下箭头按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an editable ComboBox and I wish to "hide" the down arrow button so that it looks like a normal textbox.

推荐答案

使用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();
    }
}

输出

这篇关于如何在javafx中隐藏组合框上的向下箭头按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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