Java JButton ensureButtonWidth(JButton button, int width)

Here you can find the source of ensureButtonWidth(JButton button, int width)

Description

Ensures a button has a specific minimum width.

License

BSD License

Parameter

Parameter Description
button The button to possibly elongate.
width The minimum (preferred) width for the button.

Declaration

public static final void ensureButtonWidth(JButton button, int width) 

Method Source Code

//package com.java2s;
/*/*from  ww w .  j av a 2s. c  o  m*/
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.ui classes.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */

import java.awt.Dimension;

import javax.swing.JButton;

public class Main {
    /**
     * Ensures a button has a specific minimum width.  This can be useful if
     * you have a dialog with very small-labeled buttons, such as "OK", for
     * example.  Often, very small buttons look unprofessional, so artificially
     * widening them helps.
     *
     * @param button The button to possibly elongate.
     * @param width The minimum (preferred) width for the button.
     * @see #ensureDefaultButtonWidth(JButton)
     */
    public static final void ensureButtonWidth(JButton button, int width) {
        Dimension prefSize = button.getPreferredSize();
        if (prefSize.width < width) {
            prefSize.width = width;
            button.setPreferredSize(prefSize);
        }
    }
}

Related

  1. considerarSetaComoTab(JButton comp)
  2. copyButtonWidth(JButton toButton, JButton fromButton)
  3. doButtonClick(JButton button)
  4. drawCharacter(JPanel contentPane, ActionListener listener, String url, int x, int y, List buttons)
  5. enableEnter(JButton b)
  6. enterPressesWhenFocused(final JButton button)
  7. equalizeButtons(JButton... buttons)
  8. exit(JButton aButton)
  9. fixButtonWidth(JButton... buttons)