Hybrid of slider with progress bar JavaFX

后端 未结 3 394
孤独总比滥情好
孤独总比滥情好 2021-01-05 11:15

I want to handle click on ProgressBar like on slider. and learn a percent of track. I would use slider instead progressbar but it doesn\'t have a highlighted track until th

3条回答
  •  孤城傲影
    2021-01-05 11:45

    i solved this problem with code :

    progress.setOnMouseClicked(new EventHandler() {
            @Override
            public void handle(MouseEvent event) {
                if (event.getButton() == MouseButton.PRIMARY){
                    Bounds b1 = progress.getLayoutBounds();
                    double mouseX = event.getSceneX();
                    double percent = (((b1.getMinX() + mouseX ) * 100) / b1.getMaxX());
                    //correcting a percent, i don't know when it need
                    percent -= 2;
                    progress.setProgress((percent) / 100);
                    //do something with progress in percent
                }
            }
        });
    

提交回复
热议问题