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

JTree Collapse Buttons Clipped Off Under GTK

    Details

    • Subcomponent:
    • Resolved In Build:
      b130
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      owner@owner-VirtualBox:~$ java -version
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
      owner@owner-VirtualBox:~$

      ADDITIONAL OS VERSION INFORMATION :
      owner@owner-VirtualBox:~$ lsb_release -a
      No LSB modules are available.
      Distributor ID: Ubuntu
      Description: Ubuntu 14.04 LTS
      Release: 14.04
      Codename: trusty
      owner@owner-VirtualBox:~$

      A DESCRIPTION OF THE PROBLEM :
      Collapse buttons are clipped off under the GTK look and feel making them difficult to click.
      http://i.imgur.com/IJ4BLom.png

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a JTree
      2. Add some nodes and nest them to each other in the tree
      3. Collapse some of the nodes and examine the collapse icon closely, it is clipped off by a few pixels on the top


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /// SSCCE adapted form Oracle JTree demo to reproduce OpenJDK issue.
      /// https://docs.oracle.com/javase/tutorial/uiswing/components/tree.html

      package test;

      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;
      import javax.swing.JTree;
      import javax.swing.tree.DefaultMutableTreeNode;
      import javax.swing.tree.TreeSelectionModel;
      import java.awt.Dimension;

      public class GTKTreeCollapseBug {
          private static JTree tree;

          //Optionally play with line styles. Possible values are
          //"Angled" (the default), "Horizontal", and "None".
          private static boolean playWithLineStyle = false;
          private static String lineStyle = "Horizontal";
          
          //Optionally set the look and feel.
          private static boolean useSystemLookAndFeel = false;

          private static void createNodes(DefaultMutableTreeNode top) {
              DefaultMutableTreeNode category = null;
              DefaultMutableTreeNode book = null;

              category = new DefaultMutableTreeNode("Books for Java Programmers");
              top.add(category);

              //original Tutorial
              book = new DefaultMutableTreeNode("The Java Tutorial: A Short Course on the Basics");
              category.add(book);

              //Tutorial Continued
              book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
              category.add(book);

              //JFC Swing Tutorial
              book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
              category.add(book);

              //Bloch
              book = new DefaultMutableTreeNode("Effective Java Programming Language Guide");
              category.add(book);

              //Arnold/Gosling
              book = new DefaultMutableTreeNode("The Java Programming Language");
              category.add(book);

              //Chan
              book = new DefaultMutableTreeNode("The Java Developers Almanac");
              category.add(book);

              category = new DefaultMutableTreeNode("Books for Java Implementers");
              top.add(category);

              //VM
              book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
              category.add(book);

              //Language Spec
              book = new DefaultMutableTreeNode("The Java Language Specification");
              category.add(book);
          }
              
          /**
           * Create the GUI and show it. For thread safety,
           * this method should be invoked from the
           * event dispatch thread.
           */
          private static void createAndShowGUI() {
              if (useSystemLookAndFeel) {
                  try {
                      UIManager.setLookAndFeel(
                          UIManager.getSystemLookAndFeelClassName());
                  } catch (Exception e) {
                      System.err.println("Couldn't use system look and feel.");
                  }
              }

              //Create and set up the window.
              JFrame frame = new JFrame("TreeDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              //Add content to the window.
              //Create the nodes.
              DefaultMutableTreeNode top =
                  new DefaultMutableTreeNode("The Java Series");
              createNodes(top);

              //Create a tree that allows one selection at a time.
              tree = new JTree(top);
              tree.getSelectionModel().setSelectionMode
                      (TreeSelectionModel.SINGLE_TREE_SELECTION);

              if (playWithLineStyle) {
                  System.out.println("line style = " + lineStyle);
                  tree.putClientProperty("JTree.lineStyle", lineStyle);
              }

              //Create the scroll pane and add the tree to it.
              JScrollPane treeView = new JScrollPane(tree);

              treeView.setMinimumSize(new Dimension(100, 50));

              //Add the split pane to this panel.
              frame.add(treeView);

              //Display the window.
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              // Set the GTK Look and Feel
              try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (ClassNotFoundException e) {
                e.printStackTrace();
              } catch (InstantiationException e) {
                e.printStackTrace();
              } catch (IllegalAccessException e) {
                e.printStackTrace();
              } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
              }

              //Schedule a job for the event dispatch thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }
      }

      ---------- END SOURCE ----------

      SUPPORT :
      YES

        Attachments

          Activity

            People

            • Assignee:
              ssadetsky Semyon Sadetsky (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: