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

SynthToolBarLayoutManager does not honor Component.getMinimumSize()

XMLWordPrintable

      FULL PRODUCT VERSION :
      I can reproduce on Java SE 6 update 6 and also Java SE 7 b30.

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.25-2-686-bigmem #1 SMP Fri Jun 27 04:07:13 UTC 2008 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When a component whose preferred size is larger than that of the toolbar is added to the toolbar, that component is resized to its preferred size. Instead, it should be resized in such a way that it fits into the toolbar (so long as the resulting size is larger than the component's minimum size).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached source code on GTK. Press the "jButton1" button. The combo box is resized as described above.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The combo box should be resized so that the "jButton1" is still visible. Note that this is the outcome if you comment out the UIManager.setLookAndFeel() call.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package defaultpkg;

      import java.awt.Dimension;
      import java.awt.EventQueue;
      import javax.swing.DefaultComboBoxModel;
      import javax.swing.JPanel;
      import javax.swing.UIManager;

      public class ToolBarFrame extends javax.swing.JFrame {

          public ToolBarFrame() {
              initComponents();
          }

          @SuppressWarnings("unchecked")
          // <editor-fold defaultstate="collapsed" desc="Generated Code">
          private void initComponents() {

              toolBar = new javax.swing.JToolBar();
              panel = new MyPanel();
              comboBox = new javax.swing.JComboBox();
              button = new javax.swing.JButton();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

              toolBar.setRollover(true);

              panel.setLayout(new java.awt.BorderLayout());

              comboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A short item" }));
              panel.add(comboBox, java.awt.BorderLayout.CENTER);

              toolBar.add(panel);

              button.setText("jButton1");
              button.setFocusable(false);
              button.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
              button.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
              button.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      buttonActionPerformed(evt);
                  }
              });
              toolBar.add(button);

              getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);

              pack();
          }// </editor-fold>

          private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
              DefaultComboBoxModel model = new DefaultComboBoxModel();
              model.addElement("A very very long text which should make the combo box very very wide");
              comboBox.setModel(model);
              System.out.println(panel.getMinimumSize());
      }

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

          // Variables declaration - do not modify
          private javax.swing.JButton button;
          private javax.swing.JComboBox comboBox;
          private javax.swing.JPanel panel;
          private javax.swing.JToolBar toolBar;
          // End of variables declaration

          private static final class MyPanel extends JPanel {

              @Override
              public Dimension getMinimumSize() {
                  Dimension size = super.getMinimumSize();
                  size.width = 0;
                  return size;
              }
          }
      }

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

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: