• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JavaFX Undecorated window resizing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i have a problem trying to fix the resizing system that is possible on undecorated window in JavaFX because i just have it lagged, it's not convenient at all the results you reach with inbuilt JavaFX functions.

I tried some libraries but couldn't run properly and some of them also doesn't support such functionality so my question is: what's the best solution for making a resizing undecorated window on JavaFX?

Check part of the code i have:



As you can see the problem with this resizing system is that it doesn't resize on the NW and NE direction and it lags while resizing on W.
 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah... this is unfortunate. I've seen similar problems and I'm not sure there's really a solution to make this work well in all cases. It may be related to the version of Java/JavaFX also (I don't remember issues with doing this on 8).

I did have a "frameless" project, but I can't remember what the issues were. I'll have to go take a look at it, but I'm not optimistic that I found a perfect solution to this problem. I also saw similar problems with some of the frameless implementations that others have published.

I recommend sticking to a decorated stage if you have the option. I'll post here if I find anything that might work better.
 
Kevin Ferreira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:Yeah... this is unfortunate. I've seen similar problems and I'm not sure there's really a solution to make this work well in all cases. It may be related to the version of Java/JavaFX also (I don't remember issues with doing this on 8).

I did have a "frameless" project, but I can't remember what the issues were. I'll have to go take a look at it, but I'm not optimistic that I found a perfect solution to this problem. I also saw similar problems with some of the frameless implementations that others have published.

I recommend sticking to a decorated stage if you have the option. I'll post here if I find anything that might work better.



can't work with decorated window since the program im making is a web browser  ;/

is wrapping swing for swing solutions a fine alternative to this problem?

i also tried the Borderless Scene and UndecoratorBis libs but couldn't use it properly, i don't know if it's updated you know
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, because of the need to have tabs on the very top pixel of the screen? Yeah that is important.

Using FX alongside Swing has been done before and is probably fine, especially if you limit it to just the "frame". But I don't have a ton of experience with that configuration so I can't say too much on it. Whether you "should" try that is probably going to depend on who you ask. If it works, you do what you have to do to get it done! Do be aware that Swing and JFX run on entirely different background threads, the "EDT" (Event Dispatch Thread) and the "JavaFx Application Thread", so that's where you might hit a complication. But it might be perfectly fine too...

I've definitely seen Undecorator and the other sounds familiar. Undecorator worked fine on Java 8, so maybe it's a newer JDK issue.

I found one of my projects experimenting with this stuff, with this note at the top from when I took a break to work on something else:


I think it worked OK, but not as well as I'd have liked. Unfortunately I also left it in a non-working state.

I remember seeing two performance issues. One was an initial white background (the scene "fill" background color) that briefly flashed sometimes. I mitigated that by just setting the fill color to a background similar enough to the theme color:


The other more annoying problem was component size "flickering", as containers tried to resize and catch up with the stage resizing. The multi-monitor issue IIRC was relating to resizing the edge of the window into another monitor/display, but I believe that was a solvable problem.

Not total show stoppers maybe but annoying enough that I wasn't happy with it. I definitely wasn't at a "giving up" point though. We might be able to find ways to mitigate or solve these glitches (perhaps just find a good way to throttle or slightly time-delay the stage size changes), I just found a different project I wanted to focus on more and put this on hold.

Are those the performance issues you're seeing, or are you seeing something else? Your code is doing pretty much what mine does and I don't think you're doing anything "wrong".
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, one more thing - if you're seeing other performance issues, the complexity of your scene graph is going to be a factor too. So reducing the complexity of your UI "tree" may help (or maybe some performance "tricks").
 
Kevin Ferreira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:Oh, because of the need to have tabs on the very top pixel of the screen? Yeah that is important.

Using FX alongside Swing has been done before and is probably fine, especially if you limit it to just the "frame". But I don't have a ton of experience with that configuration so I can't say too much on it. Whether you "should" try that is probably going to depend on who you ask. If it works, you do what you have to do to get it done! Do be aware that Swing and JFX run on entirely different background threads, the "EDT" (Event Dispatch Thread) and the "JavaFx Application Thread", so that's where you might hit a complication. But it might be perfectly fine too...

I've definitely seen Undecorator and the other sounds familiar. Undecorator worked fine on Java 8, so maybe it's a newer JDK issue.

I found one of my projects experimenting with this stuff, with this note at the top from when I took a break to work on something else:


I think it worked OK, but not as well as I'd have liked. Unfortunately I also left it in a non-working state.

I remember seeing two performance issues. One was an initial white background (the scene "fill" background color) that briefly flashed sometimes. I mitigated that by just setting the fill color to a background similar enough to the theme color:


The other more annoying problem was component size "flickering", as containers tried to resize and catch up with the stage resizing. The multi-monitor issue IIRC was relating to resizing the edge of the window into another monitor/display, but I believe that was a solvable problem.

Not total show stoppers maybe but annoying enough that I wasn't happy with it. I definitely wasn't at a "giving up" point though. We might be able to find ways to mitigate or solve these glitches (perhaps just find a good way to throttle or slightly time-delay the stage size changes), I just found a different project I wanted to focus on more and put this on hold.

Are those the performance issues you're seeing, or are you seeing something else? Your code is doing pretty much what mine does and I don't think you're doing anything "wrong".



The problem itself is that such resizing system is not usable, like the funny part is that to the right and bottom it works great but when it comes to a logic for the left and top its very bad and t rembling, i think 'vanilla' javafx hardly can handle such implementation for undecorated. I couldn't understand your project but you can put the code part on pastemyst (https://paste.myst.rs/)  so i try to check...
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah the left and right "resizes" are really a window move AND a resize.
It looks like your code link is incomplete, BTW.

One strategy you could try, if you can accept any downsides, would be to see if you can remove most or all of the scene temporarily during the resize drags (it could be replaced with a nice "resizing" placeholder graphic), and then re-add it all back when done. There is some cost to doing that, but if it's just at the start/end it might be okay.

You will need to make sure you maintain good view/model separation if you do that, of course. But I always recommend keeping that in focus anyway.
 
Kevin Ferreira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:Yeah the left and right "resizes" are really a window move AND a resize.
It looks like your code link is incomplete, BTW.

One strategy you could try, if you can accept any downsides, would be to see if you can remove most or all of the scene temporarily during the resize drags (it could be replaced with a nice "resizing" placeholder graphic), and then re-add it all back when done. There is some cost to doing that, but if it's just at the start/end it might be okay.

You will need to make sure you maintain good view/model separation if you do that, of course. But I always recommend keeping that in focus anyway.



what you mean removing the scene temporarily will result into? the effect itself that code into the left resizing is moving the borders while dragging, that looks so bad, don't know if it is an 'animation' issue only, you know? i am basicly open for ANYTHING that would result in a similar effect as the inbuilt DECORATED resizing system
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I spent a few minutes messing with this old code. This is quite possibly environment specific (I'm on Linux KDE Plasma), but I had an issue where I needed to call BOTH setWidth() and setHeight() when resizing the Stage, even if one of them weren't changing.

Once I fixed that in resizeStageWidth()/resizeStageHeight(), it seems to be working ok for me. Still just a little bit of flickering sometimes when doing those left/top drags, but not horrible. There's likely more optimizations and improvements possible too.

It's a little experimental code I never cleaned up and you won't be able to copy/paste this as-is, but it might give you some ideas I guess. It also gives you some hints of some other issues you might run into, such as preventing window drags off the edge of the screen. You can steal whatever you want, you may prefer that DragDirection enum to all those boolean flags. Let me know if it helps at all!

 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Ferreira wrote:
what you mean removing the scene temporarily will result into? the effect itself that code into the left resizing is moving the borders while dragging, that looks so bad, don't know if it is an 'animation' issue only, you know? i am basicly open for ANYTHING that would result in a similar effect as the inbuilt DECORATED resizing system


Yeah I am still seeing that a little bit, I think I know what you mean. The severity is quite possibly hardware performance dependent too.

What I meant by removing part of the scene is using scene.getChildren().clear() (or removing some specific children) during the drag, and then re-add those children (basically re-adding your entire UI, or most of it) back to the scene after the drag is done.



I THINK you should be able to do that without issues. You might have to re-initialize all the view stuff when you add it back into the scene (Possibly not though! You can try re-adding the old children.). That'd be highly design dependent. I'm uncertain if that would work out without causing another problem, but it's an idea that I was thinking of trying as a last resort. Ideally things should just resize with the window, but I have seen some applications here and there use this trick. It's even a performance optimization setting that some OSes support natively, when resizing or dragging windows.

If you try that and it does solve the glitchyness, you can try adding a simple container or an image to the stage which serves as an indicator to the user that they're resizing the window, which gets replaced with the real UI once the resize is done. That'd look a lot better than a blank screen during the resize, anyway.
 
Kevin Ferreira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i will study your last posts this week, but if you allow me to ask, how can i initialize the entire code of a Stack Over Flow user that posted a solution about it for JavaFX, let me show you his code:

https://paste.myst.rs/9hc26guh

i struggle to initialize the method addListenerDeeply because i call it this way ResizeHelperAlexander.addListenerDeeply(node, listener); and it doesn't recognize node or listener, can you give me a tip about it?
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like what you typed (calling it as a public static method) should work. So I guess I don't understand the error you're getting.
(I don't think I'd use a static method for that and I don't see the need for what it's doing, but technically I don't notice an issue.)

By the way, you can add code here directly easier if you click the "Code" button above and put it between the tags. Plus it ensures people coming later can see what was being discussed, in case the link breaks. But just IMO, I don't think I would use any of this code or use that addListenerDeeply() method.

I've pasted it below (with slight changes so it would build for me).
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What operating system are you on, by the way? And GPU type?

For the window flickering issue, it's possible there may just be no fix without filing a good bug report. But it would need to be a very good one which is reproducible, because I've seen some past reports for this issue that have been dismissed for one reason or another.
 
Kevin Ferreira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:What operating system are you on, by the way? And GPU type?

For the window flickering issue, it's possible there may just be no fix without filing a good bug report. But it would need to be a very good one which is reproducible, because I've seen some past reports for this issue that have been dismissed for one reason or another.



What you mean by reproducible? because this is what i will make since i don't want this small bug mess with my dream. I will probably share my report here so people can help me.

I use windows 10 with HP Inbuilt GPU = Intel Graphics 520

Gotta realize that it's not only about it flickering but the resizing itself moves the border and trembles, thats why i think it has to do with JavaFX inbuilt functionality not any graphics GPU issue.

Have you ever tried some libraries? i say this because i also struggle to implement them and couldn't success with these version of so called Borderless Scene lib, could you test it on latest JavaFX version? (There's three different versions)
I have built the path of lib and implemented so while executing its function it always has some errors, apparently followed the steps of documentation but as you are more experienced you might know how to do so, i'd be thankful if you help me.

Check the variations of Borderless Scene:

https://github.com/CatWithAWand/BorderlessSceneFX
https://github.com/goxr3plus/FX-BorderlessScene
https://github.com/NicolasSenetLarson/BorderlessScene
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, if you try submitting a bug report, let's see if any of the ranchers here are willing to help out.

By reproducible I just mean that I've seen a lot of similar bugs filed against JFX, and the devs end up closing it without any real resolution, because they couldn't see the problem themselves. So we need a good concise example to attach, and pictures/video showing the glitches.

I'm on Linux here and I've seen this stuff happen on NVidia and AMD. So we pretty much cover everything assuming we're talking about the same glitches.

Kevin Ferreira wrote:
Gotta realize that it's not only about it flickering but the resizing itself moves the border and trembles, thats why i think it has to do with JavaFX inbuilt functionality not any graphics GPU issue.



Yes the window resizing stuff won't be GPU related (flickering, maybe), but there could be two different issues combining here.

I've used at least one and maybe two of those libs before. Not sure about a third. When I get a chance I'll see if any of those try a different approach, but I suspect not.
 
Hot dog! An advertiser loves us THIS much:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic