Forum Stats

  • 3,874,118 Users
  • 2,266,686 Discussions
  • 7,911,730 Comments

Discussions

Javafx pickOnBounds setting fails with SplitPane - can't click thru a transparent SplitPane

2636066
2636066 Member Posts: 2
edited May 13, 2016 12:42PM in JavaFX 2.0 and Later

When I have a transparent SplitPane, setting pickOnBounds=false does not work, I cannot click on a button behind the splitpane. I have a splitPane with a transparent VBox with pickOnBounds=false I also set the splitpane with pickOnBounds=false, however a mouse click will not go thru to the button beneath them.

I have a button at the top that is partially covered by a SplitPane, There are buttons at the bottom that turn on/off mousetransparency and pickOnBounds.

When 'Enable MouseTransparency' is unchecked, and 'Enable Pick On Bounds' is unchecked, Then you should be able to click on the button that is behind the SplitPane, but you can't http://i.stack.imgur.com/TxUaC.png

Could it be that the skinclass of Splitpane is not inheriting the pickOnBounds setting???

Here is example code that illustrated the problem:

<span style="font-size: 8pt;">package</span><span style="font-size: 8pt;"><span class="pln">  splitpaneprob</span><span class="pun">;</span><span class="pln"><br/><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">application</span><span class="pun">.</span><span class="typ">Application</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">beans</span><span class="pun">.</span><span class="pln">binding</span><span class="pun">.</span><span class="typ">Bindings</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">geometry</span><span class="pun">.</span><span class="typ">Orientation</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">geometry</span><span class="pun">.</span><span class="typ">Pos</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="typ">Scene</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">control</span><span class="pun">.</span><span class="typ">Button</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">control</span><span class="pun">.</span><span class="typ">CheckBox</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">control</span><span class="pun">.</span><span class="typ">SplitPane</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">control</span><span class="pun">.</span><span class="typ">ToggleButton</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">layout</span><span class="pun">.</span><span class="typ">StackPane</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">scene</span><span class="pun">.</span><span class="pln">layout</span><span class="pun">.</span><span class="typ">VBox</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">import</span><span class="pln"> javafx</span><span class="pun">.</span><span class="pln">stage</span><span class="pun">.</span><span class="typ">Stage</span><span class="pun">;</span><span class="pln"><br/><br/></span><span class="com">// Demonstrates the JavaFX node mouseTransparent and pickOnBounds properties.</span><span class="pln"><br/></span><span class="com">// shows that 'PickOnBounds=false' does not work for a SplitPane that has a transparent background and you want mouseclicks to go thru</span><span class="pln"><br/></span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">PickOnBoundsFails</span><span class="pln"> </span><span class="kwd">extends</span><span class="pln"> </span><span class="typ">Application</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>   </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> main</span><span class="pun">(</span><span class="typ">String</span><span class="pun">[]</span><span class="pln"> args</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>  launch</span><span class="pun">(</span><span class="pln">args</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="pun">}</span><span class="pln"><br/><br/>   </span><span class="lit">@Override</span><span class="pln"><br/>   </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> start</span><span class="pun">(</span><span class="typ">Stage</span><span class="pln"> stage</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">Exception</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>   </span><span class="typ">ToggleButton</span><span class="pln"> testButton </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ToggleButton</span><span class="pun">(</span><span class="str">""</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="typ">VBox</span><span class="pln"> layer1 </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">VBox</span><span class="pun">();</span><span class="pln"><br/>  layer1</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="pln">testButton</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="typ">SplitPane</span><span class="pln"> layer3 </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">SplitPane</span><span class="pun">();</span><span class="pln"><br/>  layer3</span><span class="pun">.</span><span class="pln">setMaxWidth</span><span class="pun">(</span><span class="lit">140</span><span class="pun">);</span><span class="pln"><br/><br/>  layer3</span><span class="pun">.</span><span class="pln">setOrientation</span><span class="pun">(</span><span class="typ">Orientation</span><span class="pun">.</span><span class="pln">VERTICAL</span><span class="pun">);</span><span class="pln"><br/>  layer3</span><span class="pun">.</span><span class="pln">setStyle</span><span class="pun">(</span><span class="str">"-fx-background-color:transparent;-fx-border-color:teal"</span><span class="pun">);</span><span class="pln"><br/>  layer3</span><span class="pun">.</span><span class="pln">setPrefWidth</span><span class="pun">(</span><span class="lit">120</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="typ">VBox</span><span class="pln"> topItem </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">VBox</span><span class="pun">();</span><span class="pln"><br/>  topItem</span><span class="pun">.</span><span class="pln">setPickOnBounds</span><span class="pun">(</span><span class="kwd">false</span><span class="pun">);</span><span class="pln"><br/>  topItem</span><span class="pun">.</span><span class="pln">setPrefHeight</span><span class="pun">(</span><span class="lit">100</span><span class="pun">);</span><span class="pln"><br/>  topItem</span><span class="pun">.</span><span class="pln">setAlignment</span><span class="pun">(</span><span class="typ">Pos</span><span class="pun">.</span><span class="pln">BOTTOM_LEFT</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="typ">Button</span><span class="pln"> topButton </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Button</span><span class="pun">();</span><span class="pln"><br/>  topButton</span><span class="pun">.</span><span class="pln">setMouseTransparent</span><span class="pun">(</span><span class="kwd">false</span><span class="pun">);</span><span class="pln"><br/>  topItem</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="pln">topButton</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="typ">VBox</span><span class="pln"> bottomItem </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">VBox</span><span class="pun">();</span><span class="pln"><br/>   </span><span class="typ">Button</span><span class="pln"> bottomButton </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Button</span><span class="pun">(</span><span class="str">"click me"</span><span class="pun">);</span><span class="pln"><br/>  bottomItem</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="pln">bottomButton</span><span class="pun">);</span><span class="pln"><br/>  layer3</span><span class="pun">.</span><span class="pln">getItems</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="pln">topItem</span><span class="pun">);</span><span class="pln"><br/>  layer3</span><span class="pun">.</span><span class="pln">getItems</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="pln">bottomItem</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="typ">StackPane</span><span class="pln"> stack </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StackPane</span><span class="pun">();</span><span class="pln"><br/><br/>  stack</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">setAll</span><span class="pun">(</span><span class="pln">layer1</span><span class="pun">,</span><span class="pln"> layer3</span><span class="pun">);</span><span class="pln"><br/>  stack</span><span class="pun">.</span><span class="pln">setStyle</span><span class="pun">(</span><span class="str">"-fx-background-color: azure;"</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="typ">VBox</span><span class="pln"> layout </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">VBox</span><span class="pun">();</span><span class="pln"><br/>  layout</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">setAll</span><span class="pun">(</span><span class="pln"><br/>  stack</span><span class="pun">,</span><span class="pln"><br/>  createControls</span><span class="pun">(</span><span class="pln">testButton</span><span class="pun">,</span><span class="pln"> layer3</span><span class="pun">,</span><span class="pln"> topButton</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">);</span><span class="pln"><br/><br/>  stage</span><span class="pun">.</span><span class="pln">setScene</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Scene</span><span class="pun">(</span><span class="pln">layout</span><span class="pun">));</span><span class="pln"><br/>  stage</span><span class="pun">.</span><span class="pln">show</span><span class="pun">();</span><span class="pln"><br/>   </span><span class="pun">}</span><span class="pln"><br/><br/>   </span><span class="kwd">private</span><span class="pln"> </span><span class="typ">VBox</span><span class="pln"> createControls</span><span class="pun">(</span><span class="typ">ToggleButton</span><span class="pln"> controlledButton</span><span class="pun">,</span><span class="pln"> </span><span class="typ">SplitPane</span><span class="pln"> controlledNode</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Button</span><span class="pln"> buttonOnSplitPane</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>  controlledButton</span><span class="pun">.</span><span class="pln">textProperty</span><span class="pun">().</span><span class="pln">bind</span><span class="pun">(</span><span class="pln"><br/>   </span><span class="typ">Bindings</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">when</span><span class="pun">(</span><span class="pln">controlledNode</span><span class="pun">.</span><span class="pln">mouseTransparentProperty</span><span class="pun">()).</span><span class="pln">then</span><span class="pun">(</span><span class="str">"Completely Clickable"</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">otherwise</span><span class="pun">(</span><span class="typ">Bindings</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">when</span><span class="pun">(</span><span class="pln">controlledNode</span><span class="pun">.</span><span class="pln">pickOnBoundsProperty</span><span class="pun">()).</span><span class="pln">then</span><span class="pun">(</span><span class="str">"Partially clickable"</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">otherwise</span><span class="pun">(</span><span class="str">"Should Be fully Clickable"</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">);</span><span class="pln"><br/>  buttonOnSplitPane</span><span class="pun">.</span><span class="pln">textProperty</span><span class="pun">().</span><span class="pln">bind</span><span class="pun">(</span><span class="pln"><br/>   </span><span class="typ">Bindings</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">when</span><span class="pun">(</span><span class="pln">controlledNode</span><span class="pun">.</span><span class="pln">mouseTransparentProperty</span><span class="pun">()).</span><span class="pln">then</span><span class="pun">(</span><span class="str">"NOT Clickable"</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">.</span><span class="pln">otherwise</span><span class="pun">(</span><span class="str">"Clickable"</span><span class="pun">)</span><span class="pln"><br/>   </span><span class="pun">);</span><span class="pln"><br/>   </span><span class="typ">CheckBox</span><span class="pln"> enableMouseTransparency </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">CheckBox</span><span class="pun">(</span><span class="str">"Enable MouseTransparency on ScrollPane"</span><span class="pun">);</span><span class="pln"><br/>  enableMouseTransparency</span><span class="pun">.</span><span class="pln">setSelected</span><span class="pun">(</span><span class="pln">controlledNode</span><span class="pun">.</span><span class="pln">isMouseTransparent</span><span class="pun">());</span><span class="pln"><br/>  controlledNode</span><span class="pun">.</span><span class="pln">mouseTransparentProperty</span><span class="pun">().</span><span class="pln">bind</span><span class="pun">(</span><span class="pln">enableMouseTransparency</span><span class="pun">.</span><span class="pln">selectedProperty</span><span class="pun">());</span><span class="pln"><br/><br/>   </span><span class="typ">CheckBox</span><span class="pln"> enablePickOnBounds </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">CheckBox</span><span class="pun">(</span><span class="str">"Enable Pick On Bounds on ScrollPane"</span><span class="pun">);</span><span class="pln"><br/>  enablePickOnBounds</span><span class="pun">.</span><span class="pln">setSelected</span><span class="pun">(</span><span class="pln">controlledNode</span><span class="pun">.</span><span class="pln">isPickOnBounds</span><span class="pun">());</span><span class="pln"><br/>  controlledNode</span><span class="pun">.</span><span class="pln">pickOnBoundsProperty</span><span class="pun">().</span><span class="pln">bind</span><span class="pun">(</span><span class="pln">enablePickOnBounds</span><span class="pun">.</span><span class="pln">selectedProperty</span><span class="pun">());</span><span class="pln"><br/><br/>   </span><span class="typ">VBox</span><span class="pln"> controls </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">VBox</span><span class="pun">(</span><span class="lit">10</span><span class="pun">);</span><span class="pln"><br/>  controls</span><span class="pun">.</span><span class="pln">setStyle</span><span class="pun">(</span><span class="str">"-fx-background-color: cornsilk; -fx-padding: 10;"</span><span class="pun">);</span><span class="pln"><br/>  controls</span><span class="pun">.</span><span class="pln">getChildren</span><span class="pun">().</span><span class="pln">addAll</span><span class="pun">(</span><span class="pln"><br/>  enableMouseTransparency</span><span class="pun">,</span><span class="pln"><br/>  enablePickOnBounds<br/>   </span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="kwd">return</span><span class="pln"> controls</span><span class="pun">;</span><span class="pln"><br/>   </span><span class="pun">}</span><span class="pln"><br/></span></span><span style="font-size: 8pt;">}</span>

Tagged:
This discussion has been closed.