New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8269951: [macos] Focus not painted in JButton when setBorderPainted(false) is invoked #5082
Closed
+121
−1
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d782b7c
8269951: [macos] Focus not painted in JButton when setBorderPainted(f…
azuev-java d4b21ed
Test fixes
azuev-java bda9178
Changed to only paing focus ring without the entire border painting
azuev-java fefcd37
Update copyright year
azuev-java df34ab0
Remove getLookAndFeelDefaults() call
azuev-java 87ab3e3
Restore Graphics2D rendering state so we do not interfere with next s…
azuev-java 3b81c97
Restore Graphics color before leaving paintFocus()
azuev-java File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @requires (os.family == "mac") | ||
* @bug 8269951 | ||
* @summary Test checks that focus is painted on JButton even | ||
* when borders turned off | ||
* @library ../../regtesthelpers | ||
* @build Util | ||
* @run main AquaButtonFocusTest | ||
*/ | ||
|
||
|
||
import javax.swing.JButton; | ||
import javax.swing.UIManager; | ||
import java.awt.Graphics; | ||
import java.awt.image.BufferedImage; | ||
|
||
public class AquaButtonFocusTest { | ||
public static void main(String[] args) { | ||
new AquaButtonFocusTest().performTest(); | ||
} | ||
|
||
public void performTest() { | ||
try { | ||
UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Can not initialize Aqua L&F"); | ||
} | ||
|
||
FocusableButton one = new FocusableButton("One"); | ||
one.setSize(100, 100); | ||
one.setBorderPainted(false); | ||
BufferedImage noFocus = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB); | ||
Graphics g = noFocus.createGraphics(); | ||
one.paint(g); | ||
g.dispose(); | ||
BufferedImage focus = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB); | ||
one.setFocusOwner(true); | ||
g = focus.createGraphics(); | ||
one.paint(g); | ||
g.dispose(); | ||
if (Util.compareBufferedImages(noFocus, focus)) { | ||
throw new RuntimeException("Focus is not painted on JButton"); | ||
} | ||
} | ||
|
||
class FocusableButton extends JButton { | ||
private boolean focusOwner = false; | ||
|
||
public FocusableButton(String label) { | ||
super(label); | ||
} | ||
|
||
public void setFocusOwner(boolean focused) { | ||
this.focusOwner = focused; | ||
} | ||
|
||
@Override | ||
public boolean isFocusOwner() { | ||
return focusOwner; | ||
} | ||
|
||
@Override | ||
public boolean hasFocus() { | ||
return this.focusOwner; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does having 0,0 not create a problem in multiscreen environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These coordinates are relative within the Graphics clip of the button so no, that does not cause any issue. Plus, if it would then button painting would be broken already since that's exactly what is passed to the border painter in case when borders are not switched off.