Java JToolBar resizeToolBarButtons(JComponent toolbar)

Here you can find the source of resizeToolBarButtons(JComponent toolbar)

Description

Make the size of all toolbar buttons uniform.

License

Open Source License

Declaration

static public void resizeToolBarButtons(JComponent toolbar) 

Method Source Code

//package com.java2s;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JComponent;

public class Main {
    /** Make the size of all toolbar buttons uniform.
     *//*from   w  ww . j  av  a  2  s  .com*/
    static public void resizeToolBarButtons(JComponent toolbar) {
        Component[] components = toolbar.getComponents();
        int len = components.length;

        // Get the maximum dimension
        Dimension max_dim = new Dimension(0, 0);
        for (int i = 0; i < len; i++) {
            if (!(components[i] instanceof JButton))
                continue;

            Dimension size = components[i].getPreferredSize();
            if (size.width > max_dim.width)
                max_dim.width = size.width;

            if (size.height > max_dim.height)
                max_dim.height = size.height;
        }

        for (int i = 0; i < len; i++) {
            if (!(components[i] instanceof JButton))
                continue;

            JComponent jcomponent = (JComponent) components[i];
            jcomponent.setPreferredSize(max_dim);
            jcomponent.setMinimumSize(max_dim);
            jcomponent.setMaximumSize(max_dim);
            jcomponent.setSize(max_dim);
        }
    }
}

Related

  1. hideChildButtonsWithTooltip(Container parent, String tooltip)
  2. initIconButton(AbstractButton button, String toolTip)
  3. isToolBarButton(JComponent c)
  4. isToolBarButton(JComponent c)
  5. makeToolButton(URL iconURL, String cmd, String tooltip, String alt, ActionListener listener)
  6. searchFakeToolBarRecursive(Container c)
  7. setToolIcons(AbstractButton b, Icon[] icons)
  8. setToolIcons(AbstractButton b, Icon[] icons)
  9. showTextOnToolbar(javax.swing.JToolBar t, boolean show)