In the java doc it says for setMouseTransparent
that is affects all children as well as the parent.
How can it be made so only the parent's transparent areas (can see other nodes below it but not responding to mouse events) are transparent to mouse events so that the nodes below it may receive them.
This happens when stacking two XYCharts in the same pane. Only the last one added can receive events.
Set
pickOnBounds
for the relevant nodes tofalse
, then clicking on transparent areas in a node won't register a click with that node.Sample Output
This sample is actually far more complicated than is necessary to demonstrate the
pickOnBounds
function - but I just did something this complicated so that it shows what happens "when stacking twoXYCharts
in the same pane" as mentioned in the poster's question.In the sample below two line charts are stacked on top of each other and the mouse is moved over the data line in one chart which has a glow function attached to it's mouseenter event. The mouse is then moved off of the first line chart data and the glow is removed from it. The mouse is then placed over the second line chart data of an underlying stacked chart and the glow is added to that linechart in the underlying stacked chart.
This sample was developed using Java8 and the coloring and behaviour described is what I exeperienced running the program on Mac OS X and Java 8b91.
Sample Code
The code below is just for demonstrating that
pickOnBounds
does work for allowing you to pass mouse events through transparent regions stacked on top of opaque node shapes. It is not a recommended code practice to follow for styling lines in charts (you are better off using style sheets than lookups for that), it is also not necessary that you use a line chart stack to get multiple series on a single chart - it was only necessary or simpler to do these things to demonstrate the pick on bounds concept application for this answer.Note the recursive call to set the
pickOnBounds
property for the charts after the charts have been shown on a stage and all of their requisite nodes created.Sample code is an adaption of JavaFX 2 XYChart.Series and setOnMouseEntered:
Based on jewelsea answer setting top pane background color of the pane to null and
topPane.setPickOnBounds(false);
works fine:Instead of doing this:
do this:
with the folling methods.
Also you will need to make the chart in front(reverseLineChart) transparent.
The code posted in jewelsea answer does not work. To make it work I implemented the changes proposed is user1638436 answer and Julia Grabovska comment.
Here is a working version for the sake of future readers:
LineChartSample.css:
A simpler version of
turnOffPickOnBoundsFor
method: