0

My MOUSE_MOVED and MOUSE_EXIT event doesn't seem to work. Where am I getting it wrong?

   final Label captions = new Label();
        captions.setTextFill(Color.WHITE);
        captions.setStyle("-fx-font: 24 arial;");
        DropShadow shadow = new DropShadow();

  for (final PieChart.Data data : pieChart2.getData()) {    
            data.getNode().addEventHandler(MouseEvent.MOUSE_MOVED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {
                            captions.setTranslateX(e.getSceneX()+15);
                            captions.setTranslateY(e.getSceneY());
                           captions.setText(String.valueOf(data.getPieValue()) + "%");
                            captions.setVisible(true);


                        }
                    });

            data.getNode().addEventHandler(MouseEvent.MOUSE_EXITED,
                    new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent e) {

                            captions.setVisible(false);
                        }
                    });
        }

Nothing shows at all on slice hover

Amowe B
  • 35
  • 12
  • Where do you add `caption` to the scene. Furthermore have you tried making `caption` transparent to the mouse? Possibly movind the label below the cursor could otherwise result in the mouse exiting the data node. – fabian Jan 28 '19 at 11:45
  • For reference, some JavaFX `PieChart` tooltip examples are examined [here](https://stackoverflow.com/search?q=%5Bjavafx%5D+PieChart+tooltips). This [example](https://stackoverflow.com/a/44688314/230513) illustrates using [tag:jfreechart] to generate labels in a pie chart; it also enables tooltips on hovering via the call to `ChartFactory.createPieChart()`. – trashgod Jan 28 '19 at 17:05

0 Answers0