Here you can find the source of newBoxForComponent(Component c)
Parameter | Description |
---|---|
c | component |
public static Component newBoxForComponent(Component c)
//package com.java2s; /*//w w w . j a v a2s . c o m * Copyright 2008-2011 the original author or authors. * * 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. */ import java.awt.Component; import javax.swing.Box; public class Main { /** * Create a box with an aligned component using Component constants for right, center and left. * @param c component * @param alignment aligment. * @return Box with compoenent */ public static Component newBoxForComponent(Component c, float alignment) { Box box = Box.createHorizontalBox(); if (Component.RIGHT_ALIGNMENT == alignment) { box.add(Box.createHorizontalGlue()); box.add(c); } else if (Component.CENTER_ALIGNMENT == alignment) { box.add(Box.createHorizontalGlue()); box.add(c); box.add(Box.createHorizontalGlue()); } else { // default to left box.add(c); box.add(Box.createHorizontalGlue()); } return box; } /** * Create a box with a coponent aligned to left. * @param c component * @return Box with the compoenent */ public static Component newBoxForComponent(Component c) { return newBoxForComponent(c, Component.LEFT_ALIGNMENT); } }