Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261243

[macos] Swing focus indicator does not honor system accent color



    • Bug
    • Resolution: External
    • P4
    • tbd
    • 8, 11, 15, 16, 17
    • client-libs
    • macOS 10.15 or later (potentially also earlier)
      Tested on Java 11, 15, and an EA version of 17.

    • generic
    • os_x_10.15


      Traditionally, the Aqua look and feel used blue as an accent color. However, nowadays this is only a default. In recent versions of macOS (at least 10.15 and later, perhaps earlier), one can choose a custom accent color (System Preferences -> General). This color is mostly honored by Java's Aqua L&F for Swing. I.e., if the user chooses orange as system accent color, checkboxes, buttons, etc. are all rendered in orange. However, the focus ring is still rendered in blue, which looks odd and out of place.

      Note that the focus rings have largely disappeared from macOS (except for text fields). But when keyboard navigation via tabs is turned on (see https://support.apple.com/en-us/HT204434), they do appear and are rendered in a lighter version of the accent color.

      Current behavior:
      - Swing components always render focus indicators/rings in blue

      Desired behavior:
      - Mimic macOS and render focus rings in a lighter version of the accent color

      To reproduce, go to System Preferences -> General and change the accent color to orange.
      Then run:

      import javax.swing.*;
      import java.awt.*;

      public class FocusColorDemo {

          public static void main(String[] args) {
              final JFrame frame = new JFrame();
              frame.getContentPane().setLayout(new FlowLayout());
              frame.getContentPane().add(new JCheckBox("Check 1", true));
              frame.getContentPane().add(new JCheckBox("Check 2", true));
              frame.getContentPane().add(new JTextField("Field", 10));
              SwingUtilities.invokeLater(() -> {
                  frame.setBounds(200, 200, 200, 120);

      The focus indicator should appear orange, but appears blue. A screenshot is attached.


        Issue Links



              psadhukhan Prasanta Sadhukhan
              hschreiber Hendrik Schreiber
              0 Vote for this issue
              3 Start watching this issue