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

[macos] The pressed state of JToggleButton it toolbar is STILL not indicated in Aqua LnF

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, 10, 11, 12, 13, 14, 15
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:
    • Environment:

      macOS 10.14.

      java --version
      openjdk 15-ea 2020-09-15
      OpenJDK Runtime Environment (build 15-ea+34-1554)
      OpenJDK 64-Bit Server VM (build 15-ea+34-1554, mixed mode, sharing)

      Description

      Steps to reproduce:

      1. Create a JFrame with a JToolBar
      2. Add JToggleButtons to the JToolBar
      3. Click on the buttons

      Expected: the toggle button looks pressed or armed and have the special look & feel for tool bar buttons on macOS as they look in pretty much every Apple preferences pane on macOS (sample from the Mail app attached as screenshot).

      Obtained: The pressed toggle button cannot be distinguished from others

      This issue *is not yet* fixed in openjdk 15-ea 2020-09-15.

      Here's some sample code (resulting screenshot attached) that create such a frame with a toolbar with JToggleButtons. To contrast, the sample code also contains some JToggleButtons added to a regular button.

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

      public class PrefToggles {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      try {
                          // do this as the very first thing, to make sure, whatever we read as defaults are actually platform defaults
                          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              });

              final JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              final JToolBar toolBar = new JToolBar();
              toolBar.setFloatable(false);
              final Icon icon = new Icon() {
                  @Override
                  public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
                      g.fillOval(x, y, 32, 32);
                  }

                  @Override
                  public int getIconWidth() {
                      return 32;
                  }

                  @Override
                  public int getIconHeight() {
                      return 32;
                  }
              };
              toolBar.add(new JToggleButton("One", icon));
              toolBar.add(new JToggleButton("Two", icon));
              frame.getContentPane().add(toolBar, BorderLayout.NORTH);
              final JPanel regularPanel = new JPanel();
              regularPanel.add(new JToggleButton("Three", icon));
              regularPanel.add(new JToggleButton("Four", icon));
              frame.getContentPane().add(regularPanel, BorderLayout.CENTER);
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      frame.setBounds(500, 500, 500, 200);
                      frame.setVisible(true);
                  }
              });
          }
      }


      Hint: The special border for toolbar toggle buttons is set in com.apple.laf.AquaButtonUI#setThemeBorder(...) using com.apple.laf.AquaButtonUI#isOnToolbar(...). But for some reason the correct graphics are not painted as expected.

      This bug has been reported before (https://bugs.openjdk.java.net/browse/JDK-8224712), but has unfortunately not been addressed properly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              hschreiber Hendrik Schreiber
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: