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

JSeparator can't draw vertical separators under GTK

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux olgas 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      JSeparator always draws horizontal separators under the GTK look and feel, even when setting a vertical separator. This affects the separator generated by JToolbar.addSeparator() as well. Please compile and run the enclosed code to reproduce the problem.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Vertical separator.
      ACTUAL -
      Horizontal separator.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bugs;

      import java.awt.Dimension;

      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JSeparator;
      import javax.swing.SwingConstants;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;

      /**
       * Demonstrate that JSeparator can't display vertical separators under the GTK
       * look and feel in Java 6.
       * <p>
       * The first frame shows a nice vertical separator between the words "foo" and
       * "bar". The second frame shows a horizontal separator at the top of the frame
       * stretching between the words "foo" and "bar."
       *
       * @author Bill Wohler <###@###.###>
       */
      public class GtkVerticalSeparatorBug extends JFrame {
          public GtkVerticalSeparatorBug() {
              JPanel panel = new JPanel();
              BoxLayout layout = new BoxLayout(panel, SwingConstants.HORIZONTAL);
              panel.setLayout(layout);

              JLabel foo = new JLabel("foo");
              panel.add(foo);

              JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
              panel.add(separator);

              JLabel bar = new JLabel("bar");
              panel.add(bar);

              add(panel);
              panel.setPreferredSize(new Dimension(300, 20));
              pack();
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      new GtkVerticalSeparatorBug().setVisible(true);
                      try {
                          UIManager
                              .setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                      new GtkVerticalSeparatorBug().setVisible(true);
                  }
              });
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Here's a quick and ugly hack: Use a panel with an etched border. If you can suggest a better workaround (like subclassing JSeparator() and providing a better paint method), I would appreciate hearing about it.

              JPanel separator = new JPanel();
              separator.setBorder(BorderFactory.createEtchedBorder());
              Dimension d = separator.getPreferredSize();
              separator.setMinimumSize(new Dimension(2, d.height));
              separator.setPreferredSize(new Dimension(2, d.height));
              separator.setMaximumSize(new Dimension(2, d.height));

            stayer Kirill Kirichenko (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: