XTable.java :  » XML-UI » xui32 » com » xoetrope » carousel » survey » Java Open Source

Java Open Source » XML UI » xui32 
xui32 » com » xoetrope » carousel » survey » XTable.java
package com.xoetrope.carousel.survey;

import java.awt.event.MouseListener;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableColumn;


/**
 * A table extension class for managing questions
 *
 * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
 * the GNU Public License (GPL), please see license.txt for more details. If
 * you make commercial use of this software you must purchase a commercial
 * license from Xoetrope.</p>
 * <p> $Revision: 1.5 $</p>
 */
public class XTable extends JTable
{     
  public XTable()
  {
    super();    
    setAutoCreateColumnsFromModel( false );
  }
    
  public void setModel( TableModel model, XTableColumn[] columns, MouseListener listener )
  {      
    setColumnModel( new DefaultTableColumnModel() );
    setModel( model );
      
    int modelIdx = 0;
    for ( int i = 0; i < columns.length; i++ ) {
      if ( !columns[ i ].isActive() ) continue;
      DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();            
                  
      renderer.setHorizontalAlignment( columns[ i ].getAlignment() );
      TableColumn column;
      if ( columns[i].getCellEditor() == null || columns[i].getCellEditor().getComponent() instanceof JComboBox )
        column = new TableColumn( modelIdx++, columns[i].getWidth(), renderer, columns[i].getCellEditor() );
      else
        column = new TableColumn( modelIdx++, columns[i].getWidth() );
      addColumn( column );
    }
    
    addMouseListener( listener );
  }
   
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.