Here you can find the source of ensureButtonWidth(JButton button, int width)
Parameter | Description |
---|---|
button | The button to possibly elongate. |
width | The minimum (preferred) width for the button. |
public static final void ensureButtonWidth(JButton button, int width)
//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); } } }