Java JButton toolBarSeparator(JButton button, Icon icon)

Here you can find the source of toolBarSeparator(JButton button, Icon icon)

Description

Create a separator to add to a toolbar.

License

Open Source License

Parameter

Parameter Description
button The button to add to the toolBar. The height of the separator depends of the insets of the button.
icon The icon to add to the button. The height of the separator depends of the height of the icon.

Return

See below.

Declaration

public static JSeparator toolBarSeparator(JButton button, Icon icon) 

Method Source Code

//package com.java2s;
/*/*from  w  w w  .  j ava2 s.com*/
 * org.openmicroscopy.shoola.util.ui.UIUtilities
 *
 *------------------------------------------------------------------------------
 *  Copyright (C) 2006-2015 University of Dundee. All rights reserved.
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *------------------------------------------------------------------------------
 */

import java.awt.Dimension;

import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JButton;

import javax.swing.JSeparator;

import javax.swing.SwingConstants;

public class Main {
    /** Width of the separator. */
    public static final int SEPARATOR_WIDTH = 2;

    /** 
     * Create a separator to add to a toolbar. The separator needs to be 
     * set when the layout of the toolbar is reset.
     * 
     * @param button   The button to add to the toolBar. The height of the 
     *                separator depends of the insets of the button.
     * @param icon     The icon to add to the button. The height of the 
      *                 separator depends of the height of the icon.
     * @return See below.
     */
    public static JSeparator toolBarSeparator(JButton button, Icon icon) {
        JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
        if (button == null)
            return separator;
        Insets i = button.getInsets();
        int h = 0;
        if (icon != null)
            h = icon.getIconHeight();
        Dimension d = new Dimension(SEPARATOR_WIDTH, i.top + h + i.bottom);
        separator.setPreferredSize(d);
        separator.setSize(d);
        return separator;
    }
}

Related

  1. setTransparent(JButton btn)
  2. setupAutoRepeat(final JButton button, final int intervalMs)
  3. setWFActionMap(Vector actionButtons, String action, Map wfActionMap)
  4. showToolTip(final boolean show, final JWindow tip, final JButton boton, final JLabel tipText)
  5. showToolTip(final boolean show, final JWindow tip, final JButton boton, final JLabel tipText)
  6. wireComponentWithButton(JComponent component, final JButton button)