Package org.swingml.component

Source Code of org.swingml.component.TableCellComboDecorator

/* SwingML
* Copyright (C) 2002 SwingML Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors:
*     Ezequiel Cuellar <ecuellar@crosslogic.com>
*     Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
*
*/

package org.swingml.component;

import java.util.Iterator;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;

import org.swingml.model.JTableModel;
import org.swingml.model.TableColumnModel;



public class TableCellComboDecorator {
   
    public TableCellComboDecorator(JTableComponent aTable) {
        JTableModel theTableModel = (JTableModel) aTable.getModel();
        Iterator theColumns = theTableModel.getColumns().iterator();
        TableColumnModel theColumn = null;
        JComboBox theCombo = null;
        while (theColumns.hasNext()) {
            theColumn = (TableColumnModel) theColumns.next();
            if (theColumn.getType() instanceof JComboBox) {
                /*
                 Sets the cell editor to show up as a JComboBox for columns of type JComboBox.
                 It is not necesary to set a different cell renderer than the default for this case
                 */
                if (theColumn.getItems() != null) {
                    theCombo = new JComboBox(theColumn.getItems());
                    aTable.setDefaultEditor(JComboBox.class, new DefaultCellEditor(theCombo));
                }
            }
        }
    }
}
TOP

Related Classes of org.swingml.component.TableCellComboDecorator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.