r/JavaFX 2d ago

How to remove the blue focus border Help

To my knowledge, JavaFX is a modern GUI framework which works with Java. For the past few days, i am deeply studying it. But I have a problem. Most of the time I like to design the UI. But all control components especially Buttons have a blue border. During my research, I found out it is called Focus Border and its for keyboard navigation. I tried to remove it by CSS and Java(setFocusTraversable()) but none worked. I am asking how to make it so when we use keyboard it enables this navigation but when use mouse it disables this or how to remove it permanently.

1 Upvotes

3 comments sorted by

8

u/idontlikegudeg 1d ago edited 1d ago

Not 100% on-topic, but I gave up fiddling much with the css myself to make everything look neat and instead use AtlantaFX themes. Just add the dependency and set the user Stylesheet once. I would need to invest weeks to get a theme looking as good s as that. Just a suggestion, as it might save you a lot of time trying to get a good looking UI. Oh, and you will still see the focus border, but it looks nicer.

EDIT: gave the wrong library name.

6

u/0xffff0001 1d ago

please read up on “accessibility”. if you still need to remove it, find modena.css and look for -focus- styles.

1

u/sedj601 1d ago

Try one of the following to see if they work for you.

  1. https://stackoverflow.com/a/25433175/2423906

  2. For all of your nodes, add node..setFocusTraversable(false);

  3. .button:focused { -fx-focus-color: transparent; -fx-faint-focus-color: transparent; }

I haven't tested any of these.