Java 类javax.swing.table.DefaultTableColumnModel 实例源码

项目:ViolenciaContraMulher    文件:FormataTamanhoColunasJTable.java   
private static void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
            getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width;            // Obtém a largura do cabeçalho da coluna
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = renderer.getTableCellRendererComponent(
            table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;            // Obtém a largura maxima da coluna de dados
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(
                table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }
    width += 2 * margin;            // Configura a largura
    col.setPreferredWidth(width);
}
项目:Open-DM    文件:GUIHelper.java   
public static JTable autoResizeColWidth(JTable table, int extraSpaceToColumn) {
    if (extraSpaceToColumn < 0 || extraSpaceToColumn >= table.getColumnCount()) {
        throw new IllegalArgumentException("Illegal Column index.  Table " + table.getName()
                + " has " + table.getColumnCount()
                + " columns.  Can't set extra space to column " + extraSpaceToColumn);
    }

    int totalWidth = autoResizeColWidthNoFill(table);

    int availableWidth = table.getParent().getWidth();

    if (totalWidth >= availableWidth) {
        return table;
    }
    int increaseBy = availableWidth - totalWidth;

    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(extraSpaceToColumn);
    int oldWidth = col.getPreferredWidth();
    col.setPreferredWidth(oldWidth + increaseBy);

    return table;
}
项目:zencash-swing-wallet-ui    文件:AddressBookPanel.java   
private JScrollPane buildTablePanel() {
      table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
      TableColumn nameColumn = new TableColumn(0);
      TableColumn addressColumn = new TableColumn(1);
      table.addColumn(nameColumn);
      table.addColumn(addressColumn);
      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
      table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
      table.addMouseListener(new AddressMouseListener());

      // TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);

      JScrollPane scrollPane = new JScrollPane(table);
      return scrollPane;
  }
项目:Cognizant-Intelligent-Test-Scripter    文件:JtableUtils.java   
/**
 * Overriding the default re-ordering functionality.<p>
 * Re-ordering allowed if both of the i.e <code>columnIndex,newIndex</code>
 * are outside the limit.
 *
 * @param table the target tmodel
 * @param lmt re-ordering limit
 */
public static void setReorderColumn(JTable table, final int lmt) {
    table.setColumnModel(new DefaultTableColumnModel() {
        private static final long serialVersionUID = 1L;

        @Override
        public void moveColumn(int columnIndex, int newIndex) {
            if (columnIndex <= lmt) {
                return;
            } else if (newIndex <= lmt) {
                return;
            }
            super.moveColumn(columnIndex, newIndex);
        }
    });
}
项目:typewriter    文件:HighScore.java   
private final DefaultTableColumnModel getDefaultTableColumnModel() {

        final DefaultTableColumnModel dtcm = new DefaultTableColumnModel();
        final int[] sizeColumn = new int[]{36, 36, 106, 58, 42, 32, 43, 28};
        final int size = sizeColumn.length;

        TableColumn col = null;
        for (int i = 0; i < size; i++) {

            col = new TableColumn(i, sizeColumn[i]);
            col.setHeaderValue(COLUMNS.get(i));
            dtcm.addColumn(col);
        }

        return dtcm;
    }
项目:zcash-swing-wallet-ui    文件:AddressBookPanel.java   
private JScrollPane buildTablePanel() {
      table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());

      TableColumn nameColumn = new TableColumn(0);
      TableColumn addressColumn = new TableColumn(1);
      table.addColumn(nameColumn);
      table.addColumn(addressColumn);
      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
      table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
      table.addMouseListener(new AddressMouseListener());

      // TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);

      JScrollPane scrollPane = new JScrollPane(table);
      return scrollPane;
  }
项目:bigtable-sql    文件:PluginSummaryTable.java   
public PluginSummaryTable(PluginInfo[] pluginInfo, PluginStatus[] pluginStatus)
{
    super(new MyTableModel(pluginInfo, pluginStatus));

    setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    getTableHeader().setResizingAllowed(true);
    getTableHeader().setReorderingAllowed(true);
    setAutoCreateColumnsFromModel(false);
    setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);

    final TableColumnModel tcm = new DefaultTableColumnModel();
    for (int i = 0; i < s_columnWidths.length; ++i)
    {
        final TableColumn col = new TableColumn(i, s_columnWidths[i]);
        col.setHeaderValue(s_hdgs[i]);
        tcm.addColumn(col);
    }
    setColumnModel(tcm);
}
项目:bigtable-sql    文件:UpdateSummaryTable.java   
public UpdateSummaryTable(List<ArtifactStatus> artifactStatus, 
                           UpdateSummaryTableModel model) {
    super(model);
    _model = model;
    _artifacts = artifactStatus;
    setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    getTableHeader().setResizingAllowed(true);
    getTableHeader().setReorderingAllowed(true);
    setAutoCreateColumnsFromModel(false);
    setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);

    final TableColumnModel tcm = new DefaultTableColumnModel();
    JComboBox _actionComboBox = new JComboBox();
for (int i = 0; i < model.getColumnCount(); ++i) {
       final TableColumn col = new TableColumn(i, model.getColumnWidth(i));
       col.setHeaderValue(model.getColumnName(i));
       if (i == 3) {
          col.setCellEditor(new DefaultCellEditor(initCbo(_actionComboBox)));
       }
       tcm.addColumn(col);
    }
    setColumnModel(tcm);
    initPopup();
 }
项目:swingx    文件:ColumnControlButtonVisualCheck.java   
/**
 * Issue ??: Column control on changing column model.
 * 
 */
public void interactiveTestColumnControlColumnModel() {
    final JXTable table = new JXTable(10, 5);
    table.setColumnControlVisible(true);
    Action toggleAction = new AbstractAction("Set ColumnModel") {

        @Override
        public void actionPerformed(ActionEvent e) {
            table.setColumnModel(new DefaultTableColumnModel());
            table.setModel(new AncientSwingTeam());
            setEnabled(false);
        }

    };
    JXFrame frame = wrapWithScrollingInFrame(table,
            "ColumnControl: set columnModel ext -> core default");
    addAction(frame, toggleAction);
    frame.setVisible(true);
}
项目:swingx    文件:ColumnControlButtonVisualCheck.java   
/**
 * Issue ??: Column control cancontrol update on changing column model.
 * 
 */
public void interactiveTestColumnControlColumnModelExt() {
    final JXTable table = new JXTable();
    table.setColumnModel(new DefaultTableColumnModel());
    table.setModel(new DefaultTableModel(10, 5));
    table.setColumnControlVisible(true);
    Action toggleAction = new AbstractAction("Set ColumnModelExt") {

        @Override
        public void actionPerformed(ActionEvent e) {
            table.setColumnModel(new DefaultTableColumnModelExt());
            table.setModel(new AncientSwingTeam());
            table.getColumnExt(0).setVisible(false);
            setEnabled(false);
        }

    };
    JXFrame frame = wrapWithScrollingInFrame(table,
            "ColumnControl: set ColumnModel core -> modelExt");
    addAction(frame, toggleAction);
    frame.setVisible(true);
}
项目:AppWoksUtils    文件:ExtColumnModel.java   
/**
 * @param columnModel
 */
public ExtColumnModel(final TableColumnModel org) {
    super();
    this.setColumnMargin(org.getColumnMargin());
    this.setColumnSelectionAllowed(org.getColumnSelectionAllowed());
    this.setSelectionModel(org.getSelectionModel());
    for (int i = 0; i < org.getColumnCount(); i++) {
        this.addColumn(org.getColumn(i));
    }
    if (org instanceof DefaultTableColumnModel) {
        for (final TableColumnModelListener cl : ((DefaultTableColumnModel) org).getColumnModelListeners()) {
            this.addColumnModelListener(cl);
        }
    }

}
项目:compomics-utilities    文件:GeneDetailsDialog.java   
/**
 * Gets the preferred width of the column specified by colIndex. The column
 * will be just wide enough to show the column head and the widest cell in
 * the column. Margin pixels are added to the left and right (resulting in
 * an additional width of 2*margin pixels. Returns null if the max width
 * cannot be set.
 *
 * @param table the table
 * @param colIndex the colum index
 * @param margin the margin to add
 * @return the preferred width of the column
 */
public Integer getPreferredAccessionColumnWidth(JTable table, int colIndex, int margin) {

    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(colIndex);

    // get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }

    Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    int width = comp.getPreferredSize().width;

    // add margin
    width += 2 * margin;

    return width;
}
项目:cn1    文件:JTableTest.java   
public void testGetSetColumnModel() throws Exception {
    table = new JTable(3, 4);
    DefaultTableColumnModel oldModel = (DefaultTableColumnModel) table.getColumnModel();
    assertNotNull(oldModel);
    assertEquals(2, oldModel.getColumnModelListeners().length);
    assertEquals(table.getTableHeader(), oldModel.getColumnModelListeners()[0]);
    assertEquals(table, oldModel.getColumnModelListeners()[1]);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    table.setColumnModel(model);
    assertEquals(0, oldModel.getColumnModelListeners().length);
    assertEquals(2, model.getColumnModelListeners().length);
    assertEquals(0, table.getColumnModel().getColumnCount());
    assertFalse(propertyChangeController.isChanged());
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            table.setColumnModel(null);
        }
    });
}
项目:K-scope    文件:RequiredBFModel.java   
/**
 * 要求Byte/FLOP算出結果テーブル列幅を設定する.<br/>
 * 要求Byte/FLOP算出結果テーブルはすべて固定列幅とする
 * @param columnModel       テーブル列モデル
 */
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
    for (int i=0; i<columnModel.getColumnCount(); i++) {
        // 列取得
        TableColumn column = columnModel.getColumn(i);
        if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
            if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
                //column.setMinWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                //column.setMaxWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                column.setResizable(true);
            }
            else {
                column.setMinWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
                column.setResizable(false);
            }
        }
    }
}
项目:K-scope    文件:OperandTableModel.java   
/**
 * ブロック演算カウントテーブル列幅を設定する.<br/>
 * 演算カウントテーブルはすべて固定列幅とする
 * @param columnModel       テーブル列モデル
 */
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
    for (int i=0; i<columnModel.getColumnCount(); i++) {
        // 列取得
        TableColumn column = columnModel.getColumn(i);
        if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
            if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
                column.setMinWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                column.setMaxWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
                column.setResizable(false);
            }
            else {
                column.setMinWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
                column.setResizable(false);
            }
        }
    }
}
项目:K-scope    文件:VariableTableModel.java   
/**
 * 列幅を設定する
 * @param columnModel       テーブル列モデル
 */
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
    for (int i=0; i<columnModel.getColumnCount(); i++) {
        // 列取得
        TableColumn column = columnModel.getColumn(i);
        if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
            if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
                column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
            }
            else {
                column.setMinWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
                column.setResizable(false);
            }
        }
        if (HEADER_COLUMNS_MINWIDTH.length >= i) {
            if (HEADER_COLUMNS_MINWIDTH[i] >= 0) {
                column.setMinWidth(HEADER_COLUMNS_MINWIDTH[i]);
            }
        }
    }
}
项目:K-scope    文件:ProfilerTableBaseModel.java   
/**
 * 列幅を設定する
 * @param columnModel       テーブル列モデル
 */
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
    boolean[] visibled = getVisibledColumns();
    int[] preferredWidth = getHeaderColumnsPreferredWidth();
    int[] minWidth = getHeaderColumnsMinWidth();
    for (int i=0; i<columnModel.getColumnCount(); i++) {
        // 列取得
        TableColumn column = columnModel.getColumn(i);
        if (preferredWidth.length >= i) {
            if (preferredWidth[i] >= 0 && visibled[i]) {
                column.setPreferredWidth(preferredWidth[i]);
            }
            else {
                column.setMinWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
                column.setResizable(false);
            }
        }
        if (minWidth.length > i) {
            if (minWidth[i] >= 0) {
                column.setMinWidth(minWidth[i]);
            }
        }
    }
}
项目:K-scope    文件:ProfilerMeasureModel.java   
/**
 * 列幅を設定する
 * @param columnModel       テーブル列モデル
 */
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
    for (int i=0; i<columnModel.getColumnCount(); i++) {
        // 列取得
        TableColumn column = columnModel.getColumn(i);
        if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
            if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
                column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
            }
            else {
                column.setMinWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
                column.setResizable(false);
            }
        }
        if (HEADER_COLUMNS_MINWIDTH.length >= i) {
            if (HEADER_COLUMNS_MINWIDTH[i] >= 0) {
                column.setMinWidth(HEADER_COLUMNS_MINWIDTH[i]);
            }
        }
    }
}
项目:chess-game    文件:ChessbotInfoPanel.java   
private void adjustColumnSizes(JTable table, int column, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(column);
    int width;

    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }

    Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;

    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, column);
        comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
        int currentWidth = comp.getPreferredSize().width;
        width = Math.max(width, currentWidth);
    }

    width += 2 * margin;

    col.setPreferredWidth(width);
    col.setWidth(width);
}
项目:jrunalyzer    文件:LapInfoPlugin.java   
private static TableColumnModel createColumnModel(TableModel tm) {
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
    columnModel.addColumn(createColumn(COL_NR,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colNr.tile"))); //$NON-NLS-1$
    columnModel.addColumn(createColumn(COL_LAPTIME,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colLaptime.tile"))); //$NON-NLS-1$
    columnModel.addColumn(createColumn(COL_TOTALTIME,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colTotaltime.tile"))); //$NON-NLS-1$
    columnModel.addColumn(createColumn(COL_DISTANCE,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colDistance.tile"))); //$NON-NLS-1$
    columnModel.addColumn(createColumn(COL_TOTALDISTANCE,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.coltotalDistance.tile"))); //$NON-NLS-1$
    columnModel.addColumn(createColumn(COL_SPEED,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colSpeed.tile"), //$NON-NLS-1$
            new MinMaxRendererDecorator(new SpeedRenderer())));
    columnModel.addColumn(createColumn(COL_PACE,
            i18n.getText("com.github.pfichtner.jrunalyser.ui.LapInfoPlugin.colPace.tile"), //$NON-NLS-1$
            new MinMaxRendererDecorator(new PaceRenderer())));
    return columnModel;
}
项目:mafscaling    文件:Utils.java   
/**
 * Method sets columns width to the widest value
 * @param table
 * @param column
 * @param margin
 */
public static void adjustColumnSizes(JTable table, int column, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(column);
    int width;
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null)
        renderer = table.getTableHeader().getDefaultRenderer();
    Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;
    for (int r = 0; r < table.getRowCount(); ++r) {
        renderer = table.getCellRenderer(r, column);
        comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
        int currentWidth = comp.getPreferredSize().width;
        width = Math.max(width, currentWidth);
    }
    width += 2 * margin;
    col.setPreferredWidth(width);
}
项目:pdm-viewer    文件:ModelTable.java   
public ModelTable() {
    tcm = new DefaultTableColumnModel();
    tcm.addColumn(newCol("No", 50));
    tcm.addColumn(newCol("Name", 200));
    tcm.addColumn(newCol("Field Name", 200));
    tcm.addColumn(newCol("Data Type", 100));
    tcm.addColumn(newCol("comment", 100));

    DefaultTableModel dtm = new DefaultTableModel();
    this.setModel(dtm);
    this.createDefaultColumnsFromModel();
    this.setPreferredScrollableViewportSize(new Dimension(550, 30));
    // setLayout(null);
    setColumnModel(tcm);
    initializeLocalVars();
    updateUI();
}
项目:freeVM    文件:JTableTest.java   
public void testGetSetColumnModel() throws Exception {
    table = new JTable(3, 4);
    DefaultTableColumnModel oldModel = (DefaultTableColumnModel) table.getColumnModel();
    assertNotNull(oldModel);
    assertEquals(2, oldModel.getColumnModelListeners().length);
    assertEquals(table.getTableHeader(), oldModel.getColumnModelListeners()[0]);
    assertEquals(table, oldModel.getColumnModelListeners()[1]);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    table.setColumnModel(model);
    assertEquals(0, oldModel.getColumnModelListeners().length);
    assertEquals(2, model.getColumnModelListeners().length);
    assertEquals(0, table.getColumnModel().getColumnCount());
    assertFalse(propertyChangeController.isChanged());
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            table.setColumnModel(null);
        }
    });
}
项目:freeVM    文件:JTableTest.java   
public void testGetSetColumnModel() throws Exception {
    table = new JTable(3, 4);
    DefaultTableColumnModel oldModel = (DefaultTableColumnModel) table.getColumnModel();
    assertNotNull(oldModel);
    assertEquals(2, oldModel.getColumnModelListeners().length);
    assertEquals(table.getTableHeader(), oldModel.getColumnModelListeners()[0]);
    assertEquals(table, oldModel.getColumnModelListeners()[1]);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    table.setColumnModel(model);
    assertEquals(0, oldModel.getColumnModelListeners().length);
    assertEquals(2, model.getColumnModelListeners().length);
    assertEquals(0, table.getColumnModel().getColumnCount());
    assertFalse(propertyChangeController.isChanged());
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            table.setColumnModel(null);
        }
    });
}
项目:vbrowser    文件:TableModelEventHandler.java   
public void columnMarginChanged(ChangeEvent e)
{
    javax.swing.table.DefaultTableColumnModel colummodel=(DefaultTableColumnModel) e.getSource();
    TableDataProducer prod = this.tablePanel.getDataProducer(); 

    for (int i=0;i<colummodel.getColumnCount();i++) 
    {
        TableColumn column = colummodel.getColumn(i); 
        int w=column.getWidth();
        String name=column.getHeaderValue().toString();

        //Global.debugPrintf(this,"columnMarginChanged name:%s=%s\n",name,w);
        // store the new column width in the table Presentation: 

        this.tablePanel.storeColumnWidth(name,w); 
    }
}
项目:nmonvisualizer    文件:ByDataSetTable.java   
@Override
protected JTableHeader createDefaultTableHeader() {
    return new JTableHeader(getColumnModel()) {
        private static final long serialVersionUID = -9130260383688373828L;

        @Override
        public String getToolTipText(MouseEvent event) {
            super.getToolTipText(event);

            int column = getTable().convertColumnIndexToModel(
                    ((DefaultTableColumnModel) getTable().getColumnModel()).getColumnIndexAtX(event.getX()));

            // skip tooltips on Data Type and Metric columns
            if (column > 1) {
                return ((ByDataSetTableModel) getTable().getModel()).getColumnName(column);
            }
            else {
                return null;
            }
        }
    };
}
项目:cursus-ui    文件:DatabaseTableModel.java   
public void setupModel(JTable table) {
    table.setAutoCreateColumnsFromModel(false);
    table.setModel(this);
    table.setColumnModel(new DefaultTableColumnModel());
    table.setRowSorter(sorter);
    table.setSurrendersFocusOnKeystroke(true);

    TableColumnModel cols = table.getColumnModel();
    int i = 0;
    for (DatabaseColumn<T, ?> col : columns) {
        col.setModelIndex(i++);
        cols.addColumn(col);
        col.setupModel(table, this, sorter);
    }

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    table.doLayout();
}
项目:escxnat    文件:CSVTable.java   
private void initColumns()
{
    TableColumnModel colModel = new DefaultTableColumnModel();
    CSVDataModel model = getCSVModel();

    if (model == null)
        return;

    for (int c = 0; c < this.getCSVModel().getColumnCount(); c++)
    {
        TableColumn column = new TableColumn(c);
        colModel.addColumn(column);
    }

    this.setColumnModel(colModel);
}
项目:incubator-netbeans    文件:DataViewBuilders.java   
protected void setupInstance(DefaultTableColumnModel instance) {
    super.setupInstance(instance);

    for (TableColumnBuilder builder : tableColumns)
        instance.addColumn(builder.createInstance());
    instance.setColumnMargin(columnMargin); 
}
项目:Open-DM    文件:GUIHelper.java   
public static JTable autoResizeColWidth(JTable table) {
    int totalWidth = autoResizeColWidthNoFill(table);

    double availableWidth = table.getParent().getWidth();

    if (totalWidth >= availableWidth) {
        return table;
    }
    double increaseBy = availableWidth / (double) totalWidth;
    int newTotalWidth = 0;
    for (int i = 0; i < table.getColumnCount(); i++) {
        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(i);
        int oldWidth = col.getPreferredWidth();
        int newWidth = oldWidth;
        if (i < table.getColumnCount() - 1) {
            // All but the last column
            double width = (double) newWidth;
            newWidth = (int) (width * increaseBy);
        } else {
            // Last column. Make up the diff.
            newWidth = (int) availableWidth - newTotalWidth;
        }

        // Set the width
        col.setPreferredWidth(newWidth);
        newTotalWidth += newWidth;
    }

    return table;
}
项目:komodoGUI    文件:AddressBookPanel.java   
private JScrollPane buildTablePanel() {
    table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
    TableColumn nameColumn = new TableColumn(0);
    TableColumn addressColumn = new TableColumn(1);
    table.addColumn(nameColumn);
    table.addColumn(addressColumn);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
    table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
    table.addMouseListener(new AddressMouseListener());
    JScrollPane scrollPane = new JScrollPane(table);
    return scrollPane;
}
项目:zclassic-swing-wallet-ui    文件:AddressBookPanel.java   
private JScrollPane buildTablePanel() {
    table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
    TableColumn nameColumn = new TableColumn(0);
    TableColumn addressColumn = new TableColumn(1);
    table.addColumn(nameColumn);
    table.addColumn(addressColumn);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
    table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
    table.addMouseListener(new AddressMouseListener());
    JScrollPane scrollPane = new JScrollPane(table);
    return scrollPane;
}
项目:openbravo-pos    文件:JInventoryLines.java   
/** Creates new form JInventoryLines */
public JInventoryLines() {

    initComponents();

    DefaultTableColumnModel columns = new DefaultTableColumnModel();
    TableColumn c;

    c = new TableColumn(0, 200
            , new DataCellRenderer(javax.swing.SwingConstants.LEFT)
            , new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.item"));
    columns.addColumn(c);
    c = new TableColumn(1, 75
            , new DataCellRenderer(javax.swing.SwingConstants.RIGHT)
            , new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.units"));
    columns.addColumn(c);
    c = new TableColumn(2, 75
            , new DataCellRenderer(javax.swing.SwingConstants.RIGHT)
            , new DefaultCellEditor(new JTextField()));
    c.setHeaderValue(AppLocal.getIntString("label.price"));
    columns.addColumn(c);

    m_tableinventory.setColumnModel(columns);       

    m_tableinventory.getTableHeader().setReorderingAllowed(false);         
    m_tableinventory.setRowHeight(40);
    m_tableinventory.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
    m_tableinventory.setIntercellSpacing(new java.awt.Dimension(0, 1));       

    m_inventorylines = new InventoryTableModel();
    m_tableinventory.setModel(m_inventorylines);        
}
项目:EvalGUI    文件:EvalUIManager.java   
private void calcEvalTableColPrefWidth()
{
    int col = 5;
    TableColumn summaryColumn = ((DefaultTableColumnModel) summaryTable.getColumnModel()).getColumn(col);
    TableCellRenderer columnRenderer = summaryTable.getDefaultRenderer(EvalTableImplementation.EVAL_TABLE_MGR.getColumnClass(col));
    int prefCellWidth = 0;
    int prefColumnWidth = 0;
    int numRows = summaryTable.getRowCount();
    for (int row = 0; row < numRows; row++)
    {
        prefCellWidth = ((Component) columnRenderer.getTableCellRendererComponent(summaryTable, summaryTable.getValueAt(row, col), false, false, row, col)).getPreferredSize().width;
        prefColumnWidth = prefCellWidth > prefColumnWidth ? prefCellWidth : prefColumnWidth;
    }
    summaryColumn.setPreferredWidth(prefColumnWidth + 2);
}
项目:VisualDCT    文件:SpreadsheetColumnViewModel.java   
/**
    * @param dsId
 * @param dataType
 * @param displayData
 * @param loadedData
 * @throws IllegalArgumentException
 */
public SpreadsheetColumnViewModel(Object dsId, String dataType, Vector displayData,
        Vector loadedData) throws IllegalArgumentException {
    super(dsId, dataType, displayData, loadedData);
    columnModel = new DefaultTableColumnModel();
    columnModel.setColumnSelectionAllowed(true);
    refreshColumns();
}
项目:littleluck    文件:TableDemo.java   
protected TableColumnModel createColumnModel() {
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();

    TableCellRenderer cellRenderer = new OscarCellRenderers.RowRenderer(getTableRowColors());

    TableColumn column = new TableColumn();
    column.setModelIndex(OscarTableModel.YEAR_COLUMN);
    column.setHeaderValue(getString("TableDemo.yearColumnTitle", "Year"));
    column.setPreferredWidth(26);
    column.setCellRenderer(new OscarCellRenderers.YearRenderer(getTableRowColors()));
    columnModel.addColumn(column);

    column = new TableColumn();
    column.setModelIndex(OscarTableModel.CATEGORY_COLUMN);
    column.setHeaderValue(getString("TableDemo.categoryColumnTitle", "Award Category"));
    column.setPreferredWidth(100);
    column.setCellRenderer(cellRenderer);
    columnModel.addColumn(column);

    column = new TableColumn();
    column.setModelIndex(OscarTableModel.MOVIE_COLUMN);
    column.setHeaderValue(getString("TableDemo.movieTitleColumnTitle", "Movie Title"));
    column.setPreferredWidth(180);
    HyperlinkCellRenderer hyperlinkRenderer =
            new OscarCellRenderers.MovieRenderer(new IMDBLinkAction(),
                    true, getTableRowColors());
    hyperlinkRenderer.setRowColors(getTableRowColors());
    column.setCellRenderer(hyperlinkRenderer);
    columnModel.addColumn(column);

    column = new TableColumn();
    column.setModelIndex(OscarTableModel.PERSONS_COLUMN);
    column.setHeaderValue(getString("TableDemo.nomineesColumnTitle", "Nominees"));
    column.setPreferredWidth(120);
    column.setCellRenderer(new OscarCellRenderers.NomineeRenderer(getTableRowColors()));
    columnModel.addColumn(column);

    return columnModel;
}
项目:ca-iris    文件:PhotocellTableModel.java   
/** Create the table column model */
public TableColumnModel createColumnModel() {
    TableColumnModel m = new DefaultTableColumnModel();
    m.addColumn(createColumn(COL_DESCRIPTION, 120,
        I18N.get("dms.photocell.description")));
    m.addColumn(createColumn(COL_STATUS, 80,
        I18N.get("dms.photocell.status")));
    m.addColumn(createColumn(COL_READING, 80,
        I18N.get("dms.photocell.reading")));
    return m;
}
项目:ca-iris    文件:PowerTableModel.java   
/** Create the table column model */
public TableColumnModel createColumnModel() {
    TableColumnModel m = new DefaultTableColumnModel();
    m.addColumn(createColumn(COL_DESCRIPTION, 120,
        I18N.get("dms.power.description")));
    m.addColumn(createColumn(COL_TYPE, 80,
        I18N.get("dms.power.type")));
    m.addColumn(createColumn(COL_STATUS, 80,
        I18N.get("dms.power.status")));
    m.addColumn(createColumn(COL_DETAIL, 120,
        I18N.get("dms.power.detail")));
    return m;
}
项目:ca-iris    文件:PresetModel.java   
/** Create the table column model */
public TableColumnModel createColumnModel() {
    TableColumnModel m = new DefaultTableColumnModel();
    for (int i = 0; i < columns.size(); ++i)
        columns.get(i).addColumn(m, i);
    return m;
}
项目:ca-iris    文件:PresetAliasMappingModel.java   
/** Create the table column model */
public TableColumnModel createColumnModel() {
    TableColumnModel m = new DefaultTableColumnModel();
    for (int i = 0; i < columns.size(); ++i)
        columns.get(i).addColumn(m, i);
    return m;
}