From eba80e3f36eb68ef3670367ff19d78fdf8d231b3 Mon Sep 17 00:00:00 2001 From: Jannis Weis <31143295+weisJ@users.noreply.github.com> Date: Mon, 2 May 2022 21:21:29 +0200 Subject: [PATCH] Button: Implicitly set isRequestFocusEnabled to false for borderless variants --- .../weisj/darklaf/ui/button/DarkButtonListener.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java index cf036831..624206f9 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2020-2021 Jannis Weis + * Copyright (c) 2020-2022 Jannis Weis * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, @@ -87,6 +87,16 @@ public class DarkButtonListener extends BasicButtonListe ui.updateMargins(b); b.doLayout(); b.repaint(); + if (ButtonConstants.KEY_VARIANT.equals(key)) { + // We only have to check the explicit variant, as automatic conversion implies the button is + // non-focusable anyway. + boolean oldWasBorderless = ButtonConstants.VARIANT_BORDERLESS.equals(e.getOldValue()) + || ButtonConstants.VARIANT_BORDERLESS_RECTANGULAR.equals(e.getOldValue()); + boolean newIsBorderless = ButtonConstants.isBorderless(b) || ButtonConstants.isBorderlessRectangular(b); + if (oldWasBorderless || newIsBorderless) { + b.setRequestFocusEnabled(!newIsBorderless); + } + } } } }