`PopupWindow` will always overwrite its `Scene` (user agent) stylesheets when 
an owner was set and `show` is called.
Code like this:


        final Popup popup = new Popup();
        popup.getScene().setUserAgentStylesheet(popupUserAgentStylesheet);
        popup.getScene().getStylesheets().add(popupStylesheet);


will do nothing, because your added stylesheets will be later overwritten when 
`show` is called. 
Andy and I were already wondering about this behavior two years ago: 
https://github.com/openjdk/jfx/pull/1394#discussion_r1617620949

---

I can't see any reason why we should do that. Instead, this PR will only add 
the stylesheets of the owner if they do not exist already. 
Additionally, we will not overwrite the user agent stylesheet if it was already 
set.

Added tests for all combinations I can think of. This PR also fixes NPEs that 
can happen when the owner window has no 'root window'.

There is already a test for the `Cursor` behavior, but there was none that 
verifies that the `Cursor` is not overwritten, so added one as well.

https://github.com/openjdk/jfx/blob/05a7b6d0db5e799395da27ab43a93d4337001e11/modules/javafx.graphics/src/main/java/javafx/stage/PopupWindow.java#L479-L481

Now, we will never overwrite anything that the developer set (before 
`show`ing). And as we can see above, this was already done this way with the 
`Cursor`.


---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - 2 more tests to check that we indeed do not add the same stylesheet twice
 - 8389092: PopupWindow.show() unconditionally overwrites user-set scene 
stylesheets with the owner's stylesheets

Changes: https://git.openjdk.org/jfx/pull/2236/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2236&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8389092
  Stats: 151 lines in 2 files changed: 131 ins; 8 del; 12 mod
  Patch: https://git.openjdk.org/jfx/pull/2236.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2236/head:pull/2236

PR: https://git.openjdk.org/jfx/pull/2236

Reply via email to