Here you can find the source of setPreferredWidth(final JComponent component, final int width)
Parameter | Description |
---|---|
component | the component |
width | the width |
public static void setPreferredWidth(final JComponent component, final int width)
//package com.java2s; /************************************************************************** * alpha-Flow: distributed case files in form of active documents * (supporting knowledge-driven ad-hoc processes in healthcare) * ============================================== * Copyright (C) 2009-2012 by //w ww . jav a 2s .c om * - Christoph P. Neumann (http://www.chr15t0ph.de) ************************************************************************** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ************************************************************************** * $Id: Swing_Helper.java 3583 2012-02-16 01:52:45Z cpn $ *************************************************************************/ import java.awt.Dimension; import javax.swing.JComponent; public class Main { /** * Sets the width of a JComponent without changing its height. * * @param component * the component * @param width * the width */ public static void setPreferredWidth(final JComponent component, final int width) { final int height = (int) component.getPreferredSize().getHeight(); component.setPreferredSize(new Dimension(width, height)); } }