2

It seems like the behavior of SubScene or TabPane isn't what i was expecting or something is wrong with it.

Because Instead of Being Focused on Subscene [*1.] when i click on Subscene it focuses on TabPane. Even when i force it to focus on the SubScene it forces back & focuses on TabPane [*2.]

  1. (Is in grey color & it is inside a tab)
  2. (as seen on Debug console, 3rd GIF)

Replicating the Issue:

(How to test the issue by yourself)

  • Add a TabPane & a Tab
  • Add a SubScene Inside the Tab
  • Check By Clicking On SubScene Where it Focuses By Printing:
  SubScene.getScene().getFocusOwner().getId();

Main.java | Controller.Java | sample.fxml | (Or just Copy Paste)

.

Issue Effect:

| sub-scene |

enter image description here

| sub-scene.getScene() |

enter image description here

double-beep
  • 5,031
  • 17
  • 33
  • 41
Giorgos Xou
  • 1,461
  • 1
  • 13
  • 32
  • Key events are delivered to the node that has the focus. Events also travel down the scene graph to the target and then bubble back up to the window. If the neither sub-scene nor any of its descendants have the focus then the key event won't reach the sub-scene. Also, in the case a descendant has the focus, if the key event is consumed before reaching the sub-scene then the sub-scene again won't receive the event. – Slaw Aug 24 '19 at 03:17
  • @Slaw i get the fact that `"Key events are delivered to the node that has the focus ...also travel down the scene graph"` but isn't supposed to be focused on sub-**scene** when i already have clicked on the layout of sub-**scene**? _(because it doesn't focus, it seems like it works only for nodes down the sub-**scene**'s graph and not for sub-**scene** itself)_ – Giorgos Xou Aug 24 '19 at 04:07
  • to give you an idea, when i set `scene.requestFocus();` on **MouseEvents** and then observe the behavior of focus-Event it seems like when i click on the layout of sub-**scene** it **loses** focus and then **gains** it back each time i click on it... – Giorgos Xou Aug 24 '19 at 04:33
  • * *(i've updated my post with one more gif for that)* * – Giorgos Xou Aug 24 '19 at 04:51
  • 1
    Please provide a [mcve] that demonstrates the problem. Unrelated to your problem: please learn java naming conventions and stick to them. – kleopatra Aug 24 '19 at 10:20
  • @kleopatra I think it was minimal and demonstrated the problem well enough untill i came accross "other" issues and i added the **[Extra info]** section for that reason, but still you are right i have to reedit it somehow ..., for now though i have not that much time to do it... `please learn java naming conventions` i'm gonna try more if i was wrong anywhere... – Giorgos Xou Aug 24 '19 at 10:32
  • * *(ReEddited)* * – Giorgos Xou Aug 24 '19 at 18:54
  • 1
    My first comment was general information since I don't know enough about your application to provide more specific help. When asking a question like this (_Why isn't this code working?_) you need to provide a [mre] (← read link). You currently describe a problem, give a vague description of the scene graph structure, and provide some GIFs as proof the problem exists. However, you haven't actually provided any code for us to look at and try ourselves. Please _create_ an example application that demonstrates the problem and then [edit] it into your question—as formatted text, not images. – Slaw Aug 25 '19 at 03:39
  • * *(ReEddited, Done)* * – Giorgos Xou Aug 25 '19 at 07:04
  • 1
    Try `scene.setOnMousePressed(e -> { scene.requestFocus(); e.consume(); })`. If the mouse-pressed event reaches the tab pane (or something related to the tab pane, not sure) then it requests focus. And regarding naming conventions, variables use `camelCase`. – Slaw Aug 25 '19 at 08:20
  • @Slaw What kind of **sorcery** is this ```e.consume();``` it actually works , you have made my day **Thanks you very much!** because whenever i stack on an issue most of the times it is like i can't continue and do anything else unless i find out the reason [...] – Giorgos Xou Aug 25 '19 at 08:58
  • But the real question is ```should that thing actually be happening or not?``` – Giorgos Xou Aug 25 '19 at 08:59
  • 1
    Yes, the behavior makes sense. If the mouse is pressed somewhere inside a tab and none of the nodes consume the event then the tab pane should become focused. To understand more about event processing, such as what `consume()` does, see https://docs.oracle.com/javase/8/javafx/events-tutorial/events.htm – Slaw Aug 25 '19 at 09:18

0 Answers0