AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-20353393

Ronin's questions

Martin Hope
Ronin
Asked: 2023-12-02 04:21:22 +0800 CST

重置/清除/取消选择选择框 javaFX

  • 6

内联图像

当用户在同一框中选择另一个选项时,我一直试图取消选择或清除选择框的值。当我选择一个汽车品牌,然后选择另一个汽车品牌时,所有选择都会显示,如果我选择相同的一个,图像将重复,第一个图像将留空,仅保留按钮...我已尝试/ setValue null/isVisible /setVisible/ 但按钮的空间仍然存在......我什至尝试做 getchildren 删除......我迷路了..



public class HelloController implements Initializable {
    private Stage stage;
    private Scene scene;
    private Parent root;

    @FXML private Label lbMake;
    @FXML private Label lbBody;
    @FXML private Label lbColor;
    @FXML private Label lbEngine;
    @FXML private Label lbPerformance;
    @FXML private Label lbPrice;

    @FXML private TilePane tilePaneMain;

    @FXML private ChoiceBox<String> cbMake;
    @FXML private ChoiceBox<String> cbColor;
    @FXML private ChoiceBox<String> cbPerformance;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        displayGallery();

        cbMake.getItems().addAll("Clear Choice","Aston Martin","BMW","Ferrari","Genesis","Hummer","Lamborghini","Lincoln","Lucid","Maserati","Maybach","McLaren","Rolls-Royce","Tesla");
        cbMake.setOnAction(this::getMake);

        cbColor.getItems().addAll("Clear Choice","black","blue","green","orange","red","white","yellow","gold");
        cbColor.setOnAction(this::getColor);

        cbPerformance.getItems().addAll("Clear Choice","2.3","2.5","2.7","3.0","3.6","3.8","4.2");
        cbPerformance.setOnAction(this::getPerformance);

    }


    // This is the constructors for the data.
    Cars car0 = new Cars("Aston Martin", "220000.00", "black", "8", "3.6", new ImageView(new Image(getClass().getResourceAsStream("/car0.jpg"))),"yes");
    Cars car1 = new Cars("Aston Martin", "220000", "blue", "8", "3.6", new ImageView(new Image(getClass().getResourceAsStream("/car1.jpg"))),"no");
    Cars car2 = new Cars("Aston Martin", "220000", "green", "8", "3.6", new ImageView(new Image(getClass().getResourceAsStream("/car2.jpg"))),"no");
    Cars car3 = new Cars("Aston Martin", "220000", "red", "8", "3.6", new ImageView(new Image(getClass().getResourceAsStream("/car3.jpg"))),"yes");
    Cars car4 = new Cars("Cadillac", "110000", "blue", "0", "4.8", new ImageView(new Image(getClass().getResourceAsStream("/car4.jpg"))),"no");
    Cars car5 = new Cars("Cadillac", "110000", "red", "0", "4.8", new ImageView(new Image(getClass().getResourceAsStream("/car5.jpg"))),"no");
    Cars car6 = new Cars("Maserati", "200000", "black", "8", "3.8", new ImageView(new Image(getClass().getResourceAsStream("/car6.jpg"))),"no");
    Cars car7 = new Cars("Maserati", "200000", "blue", "8", "3.8", new ImageView(new Image(getClass().getResourceAsStream("/car7.jpg"))),"no");
    Cars car8 = new Cars("Maserati", "200000", "red", "8", "3.8", new ImageView(new Image(getClass().getResourceAsStream("/car8.jpg"))),"no");
    Cars car9 = new Cars("Maserati", "200000", "white", "8", "3.8", new ImageView(new Image(getClass().getResourceAsStream("/car9.jpg"))),"yes");
    Cars car10 = new Cars("Lamborghini", "400000", "black", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car10.jpg"))),"no");
    Cars car11 = new Cars("Lamborghini", "400000", "black", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car11.jpg"))),"yes");
    Cars car12 = new Cars("Lamborghini", "400000", "blue", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car12.jpg"))),"yes");
    Cars car13 = new Cars("Lamborghini", "400000", "green", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car13.jpg"))),"no");
    Cars car14 = new Cars("Lamborghini", "400000", "white", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car14.jpg"))),"no");
    Cars car15 = new Cars("Lamborghini", "400000", "yellow", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car15.jpg"))),"no");
    Cars car16 = new Cars("McLaren", "365000", "yellow", "8", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car16.jpg"))),"no");
    Cars car17 = new Cars("McLaren", "365000", "blue", "8", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car17.jpg"))),"no");
    Cars car18 = new Cars("McLaren", "365000", "green", "8", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car18.jpg"))),"no");
    Cars car19 = new Cars("McLaren", "365000", "black", "8", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car19.jpg"))),"no");
    Cars car20 = new Cars("McLaren", "365000", "red", "8", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car20.jpg"))),"no");
    Cars car21 = new Cars("McLaren", "400000", "orange", "10", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car21.jpg"))),"yes");
    Cars car22 = new Cars("Ferrari", "400000", "black", "12", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car22.jpg"))),"yes");
    Cars car23 = new Cars("Ferrari", "400000", "blue", "12", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car23.jpg"))),"yes");
    Cars car24 = new Cars("Ferrari", "400000", "red", "8", "2.7", new ImageView(new Image(getClass().getResourceAsStream("/car24.jpg"))),"no");
    Cars car25 = new Cars("Ferrari", "400000", "white", "12", "2.5", new ImageView(new Image(getClass().getResourceAsStream("/car25.jpg"))),"yes");
    Cars car26 = new Cars("Ferrari", "400000", "white", "8", "2.7", new ImageView(new Image(getClass().getResourceAsStream("/car26.jpg"))),"no");
    Cars car27 = new Cars("Ferrari", "400000", "yellow", "8", "2.7", new ImageView(new Image(getClass().getResourceAsStream("/car27.jpg"))),"no");
    Cars car28 = new Cars("Lincoln", "365000", "black", "12", "4.2", new ImageView(new Image(getClass().getResourceAsStream("/car28.jpg"))),"no");
    Cars car29 = new Cars("Lincoln", "365000", "gray", "12", "4.2", new ImageView(new Image(getClass().getResourceAsStream("/car29.jpg"))),"no");
    Cars car30 = new Cars("Hummer", "180000", "blue", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car30.jpg"))),"no");
    Cars car31 = new Cars("Hummer", "180000", "orange", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car31.jpg"))),"no");
    Cars car32 = new Cars("Hummer", "180000", "white", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car32.jpg"))),"no");
    Cars car33 = new Cars("Hummer", "180000", "gray", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car33.jpg"))),"no");
    Cars car34 = new Cars("Hummer", "180000", "white", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car34.jpg"))),"no");
    Cars car35 = new Cars("Lucid", "150000", "blue", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car35.jpg"))),"no");
    Cars car36 = new Cars("Lucid", "150000", "red", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car36.jpg"))),"no");
    Cars car37 = new Cars("Lucid", "150000", "white", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car37.jpg"))),"no");
    Cars car38 = new Cars("Rivian", "100000", "red", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car38.jpg"))),"no");
    Cars car39 = new Cars("Rivian", "100000", "blue", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car39.jpg"))),"no");
    Cars car40 = new Cars("Maybach", "400000", "red", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car40.jpg"))),"no");
    Cars car41 = new Cars("BMW", "250000", "gold", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car41.jpg"))),"no");
    Cars car42 = new Cars("Rolls-Royce", "500000", "gold", "0", "3.0", new ImageView(new Image(getClass().getResourceAsStream("/car42.jpg"))),"no");
    Cars car43 = new Cars("Genesis", "300000", "white", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car43.jpg"))),"yes");
    Cars car44 = new Cars("Tesla", "50000", "gray", "0", "2.3", new ImageView(new Image(getClass().getResourceAsStream("/car44.jpg"))),"no");

    // This is adding the constructor to an Array
    public ArrayList<Cars> getList() {
        ArrayList<Cars> carList = new ArrayList<>();
        return carList;
    }


    // This display the gallery to the opening scene.
    public void displayGallery() {
            int i =0;
        for (i = 0; i < getList().size(); i++) {
            ImageView imageView = new ImageView(new Image(getClass().getResourceAsStream("/car" + i + ".jpg")));
            imageView.setFitWidth(200);
            imageView.setFitHeight(155);
            Button btnGallery = new Button(Integer.toString(i),imageView);
            int finalI = i;
            btnGallery.setOnMouseEntered(event->{
                //btnGallery.setTextFill(Color.PURPLE);
                lbMake.setText(getList().get(finalI).getMake());
                lbColor.setText(getList().get(finalI).getColor());
                lbPerformance.setText(getList().get(finalI).getPerformance());
                lbPrice.setText(getList().get(finalI).getPrice());
                lbEngine.setText(getList().get(finalI).getCylinder());
                lbBody.setText(getList().get(finalI).getIsConvertable());

            });
            btnGallery.setOnMouseExited(event->{
                //btnGallery.setTextFill(Color.BLACK);
                lbMake.setText("");
                lbColor.setText("");
                lbPerformance.setText("");
                lbPrice.setText("");
                lbEngine.setText("");
                lbBody.setText("");


            });
            btnGallery.setOnAction(ae-> {
                    try {
                        String btnText = btnGallery.getText();
                        ArrayList<Cars> passList = getList();
                        FXMLLoader loader = new FXMLLoader(getClass().getResource("payment-view.fxml"));
                        root = loader.load();
                        PaymentController paymentController = loader.getController();
                        paymentController.displayName(btnText);
                        paymentController.getArrayList(passList);
                        stage = (Stage) ((Node) ae.getSource()).getScene().getWindow();
                        scene = new Scene(root);
                        stage.setScene(scene);
                        stage.show();

                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
            });
            //tilePaneMain.getChildren().add(btnGallery);
        }
    }
// Display results but doesn't remove previous selection once another is made, if another enter //image description herechoice box selction is made,if images duplicate then empty buttons //remain.
    private void getMake(ActionEvent actionEvent) {
        for (int index = 0; index < getList().size();index++){
            if ((getList().get(index).getMake().contains(cbMake.getValue()))){
                getList().get(index).getImage().setFitWidth(175);
                getList().get(index).getImage().setFitHeight(150);
                Button btnMake = new Button();
                btnMake.setGraphic(getList().get(index).getImage());
                tilePaneMain.getChildren().add(btnMake);
            }
        }
    }
    private void getColor(ActionEvent actionEvent) {
        for (int index = 0; index < getList().size();index++){
            if ((getList().get(index).getColor().contains(cbColor.getValue()))){
                getList().get(index).getImage().setFitWidth(175);
                getList().get(index).getImage().setFitHeight(150);
                Button btnMake = new Button();
                btnMake.setGraphic(getList().get(index).getImage());
                tilePaneMain.getChildren().add(btnMake);
            }
        }
    }
    private void getPerformance(ActionEvent actionEvent) {
        for (int index = 0; index < getList().size();index++){
            if ((getList().get(index).getPerformance().contains(cbPerformance.getValue()))){
                getList().get(index).getImage().setFitWidth(175);
                getList().get(index).getImage().setFitHeight(150);
                Button btnMake = new Button();
                btnMake.setGraphic(getList().get(index).getImage());
                tilePaneMain.getChildren().add(btnMake);
            }
        }
    }
}
image
  • 1 个回答
  • 34 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve