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

Docking point of a floating toolbar changes after closing

XMLWordPrintable

    • b04
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If a toolbar needs to make floating (with ui.setFloating(true,null) the constraintBeforeFloating is not correct saved
      Line 791
      if (dockingSource == null)
      {
          dockingSource = toolBar.getParent();
          dockingSource.remove(toolBar);
      }
      constraintBeforeFloating = calculateConstraint();

      because the remove function removes from the layout the toolbar, and is impossible to determinate constraintBeforeFloating correctly

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JToolBar at the EAST side. At construction call the setFloating method of the ui. If closing the floating toolbar, it comes to the NORTH side.

      Here is a simple frame having only a toolbar. You can reproduce the error with a simple default frame without any program

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * This program part set the toolbar to floating state
       * Closing the toolbar cause the toolbar go to the NORTH side instead
      EAST as
       * was defined in initComponents.
       * If you comment this part the error can be reproduced too
       * Move the toolbar to the floating position, and close it. It will be
      come back
       * to the NORT side
       * If the toolbar is moved betwwen sides, afterwards it works fine
       * The problem caused by the unplug described in the previuosly mail
       */

      /*
       * TBProblem.java
       *
       * Created on 06. Februar 2008, 19:36
       */

      package toolbarproblem;

      import java.util.Timer;
      import javax.swing.plaf.basic.BasicToolBarUI;

      /**
       *
       * @author Apa
       */
      public class TBProblem extends javax.swing.JFrame {
         
          /** Creates new form TBProblem */
          public TBProblem() {
              initComponents();
      /*
       * This program part set the toolbar to floating state
       * Closing the toolbar cause the toolbar go to the NORTH side instead
      EAST as
       * was defined in initComponents.
       * If you comment this part the error can be reproduced too
       * Move the toolbar to the floating position, and close it. It will be
      come back
       * to the NORT side
       * If the toolbar is moved betwwen sides, afterwards it works fine
       * The problem caused by the unplug described in the previuosly mail
       */
              if (false) {
                  BasicToolBarUI ui=(BasicToolBarUI) jToolBar1.getUI();
                  ui.setFloating(true, null);
              }
          }
         
          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          // <editor-fold defaultstate="collapsed" desc="Generated
      Code">//GEN-BEGIN:initComponents
          private void initComponents() {

              jToolBar1 = new javax.swing.JToolBar();
              jButton1 = new javax.swing.JButton();
              jPanel1 = new javax.swing.JPanel();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

              jToolBar1.setRollover(true);

              jButton1.setText("jButton1");
              jButton1.setFocusable(false);
              
      jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
              jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
              jToolBar1.add(jButton1);

              getContentPane().add(jToolBar1, java.awt.BorderLayout.EAST);

              javax.swing.GroupLayout jPanel1Layout = new
      javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                  
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 340, Short.MAX_VALUE)
              );
              jPanel1Layout.setVerticalGroup(
                  
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 300, Short.MAX_VALUE)
              );

              getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

              pack();
          }// </editor-fold>//GEN-END:initComponents
         
          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new TBProblem().setVisible(true);
                  }
              });
          }
         
          // Variables declaration - do not modify//GEN-BEGIN:variables
          private javax.swing.JButton jButton1;
          private javax.swing.JPanel jPanel1;
          private javax.swing.JToolBar jToolBar1;
          // End of variables declaration//GEN-END:variables
         
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
                  ui.setFloating(false,null); //need call it independent that the tb is not floating it will initialize the dockingSource
                  ((BorderLayout)lm).removeLayoutComponent(tb);
                  ((BorderLayout)lm).addLayoutComponent(tb,into);
                  tb.setOrientation(orient);
                  Rectangle bound=reMap();
                  ui.setFloatingLocation(bound.x,bound.y);
                  ui.setFloating(true,null);
      There is a simpler test case:
      === Source Begin ===
      /**
       * Test demonstrates a bug in JToolBar.
       * How to reproduce:
       * 1. Run the tes
       * 2. Make the toolbar floating by mouse dragging
       * 3. Close toolbar
       * 4. Note that it is stuck to the NORTH side instead of the EAST side.
       */
      import javax.swing.*;
      import java.awt.*;

      public class Test extends JFrame {

          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new Test().setVisible(true);
                  }
              });
          }

          public Test() {
              JToolBar toolBar1 = new JToolBar();
              toolBar1.add(new JLabel("Label"));
              add(toolBar1, BorderLayout.EAST);

              setSize(400, 300);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLocationRelativeTo(null);
          }
      }
      === Source End ===

            psadhukhan Prasanta Sadhukhan
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: