Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 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. /
 package org.apache.cayenne.modeler.util;
 import java.awt.Color;
 import java.awt.Font;
Utility class to create standard Swing widgets following default look-and-feel of CayenneModeler.

Andrei Adamchik
 // TODO: (Andrus) investigate performance impact of substituting
 // constructors for all new widgets with cloning the prototype
 public class CayenneWidgetFactory {

Not intended for instantiation.
     protected CayenneWidgetFactory() {

Creates a new JComboBox with a collection of model objects.
     public static JComboBox createComboBox(Collection modelboolean sort) {
         return createComboBox(model.toArray(), sort);

Creates a new JComboBox with an array of model objects.
     public static JComboBox createComboBox(Object[] modelboolean sort) {
         JComboBox comboBox = CayenneWidgetFactory.createComboBox();
         if (sort) {
         comboBox.setModel(new DefaultComboBoxModel(model));
         return comboBox;

Creates a new JComboBox.
     public static JComboBox createComboBox() {
         JComboBox comboBox = new JComboBox();
         return comboBox;

Creates a new JTextField with a default columns count of 20.
     public static JTextField createTextField() {
         return createTextField(20);

Creates a new JTextField with a specified columns count.
     public static JTextField createTextField(int columns) {
         final JTextField textField = new JTextField(columns);
        return textField;
    protected static void initTextField(final JTextField textField) {
        // config focus
        textField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // transfer focus

Initializes a "form" element with a standard font and height.
    protected static void initFormWidget(JComponent component) {
        component.setFont(component.getFont().deriveFont(., 12));
         * Dimension size = component.getPreferredSize(); if (size == null) { size = new
         * Dimension(); } size.setSize(size.getWidth(), 20);
         * component.setPreferredSize(size);

Creates a borderless button that can be used as a clickable label.
    public static JButton createLabelButton(String text) {
        JButton but = createButton(text);
        but.setMargin(new Insets(0, 0, 0, 0));
        return but;

Creates a normal button.
    public static JButton createButton(String text) {
        return new JButton(text);
New to GrepCode? Check out our FAQ X