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

BasicSplitPaneDivider:oneTouchExpandableChanged() returns leftButton and rightButton as null with GTKLookAndFeel

    XMLWordPrintable

Details

    Description

      There is unspecified behavior of BasicSplitPaneDivider:oneTouchExpandableChanged() spec when run with -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel.

      Spec says
      https://download.java.net/java/early_access/jdk17/docs/api/java.desktop/javax/swing/plaf/basic/BasicSplitPaneDivider.html#oneTouchExpandableChanged()
      "it will create the leftButton and rightButton if they are null."
       
      Generally, by calling oneTouchExpandableChanged(), leftButton and rightButton should be created if they are null.
      But with GTKLookAndFeel,oneTouchExpandableChanged() does not initialize leftButton and rightButton. They remain null.

      If the behavior of the BasicSplitPaneDivider::oneTouchExpandableChanged() varies based on Look and feel then this should be stated explicitly in spec.

      Code snippet:
      class BasicImpl extends BasicSplitPaneDivider {
          public JButton leftB;
          public JButton rightB;
          public BasicImpl(BasicSplitPaneUI ui) {
              super(ui);
          }
          @Override
          protected void oneTouchExpandableChanged() {
              super.oneTouchExpandableChanged();
              this.leftB = super.leftButton;
              this.rightB = super.rightButton;
          }
      }

      public class SplitTests {
          public static void main(String[] args) {
              new SplitTests().test();
          }
          public void test(){
              BasicSplitPaneUI splitPaneUIS = new BasicSplitPaneUI(){};
              JSplitPane splitPane = new JSplitPane();
              splitPane.setOneTouchExpandable(true);
              splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
              splitPaneUIS.installUI(splitPane);
              BasicImpl basic= new BasicImpl(splitPaneUIS);
              basic.oneTouchExpandableChanged();
              if(basic.leftB != null && basic.rightB != null)
                  System.out.println("Expected : left and right Button created.");
              else
                  System.out.println("Unexpected : buttons are null. " +basic.rightB+ " "+basic.leftB);
          }
      }

      Obeservation:
      =====
      /scratch/jdk-cache/17/34/jdk-17/bin/java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel SplitTests
      Unexpected : buttons are null. null null

      /scratch/jdk-cache/17/34/jdk-17/bin/java SplitTests
      Expected : left and right Button created.

      Attachments

        Issue Links

          Activity

            People

              pbansal Pankaj Bansal (Inactive)
              amadgundi Asha Madgundi (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: