Package javax.swing.table

Examples of javax.swing.table.DefaultTableColumnModel


    JMTableColumn server_info_param_column = new JMTableColumn();
    server_info_param_column.setModelIndex(1);
    server_info_param_column.setHeaderValue(" ");
    server_info_param_column.setCellRenderer(new ServerInfoParamCellRenderer());
   
    TableColumnModel column_model = new DefaultTableColumnModel();
    column_model.addColumn(server_info_label_column);
    column_model.addColumn(server_info_param_column);
   
    this.setModel(new ServerInfoTableModel());
    this.setColumnModel(column_model);
  }
View Full Code Here


                  if( o1_order < o2_order ) return -1;
                  if( o1_order > o2_order ) return 1;
              return 0;
      }
    });   
    TableColumnModel column_model = new DefaultTableColumnModel();   
    for(TableColumnExt column : table_columns) {
      column_model.addColumn(column);
    }   
    column_model.setColumnMargin(0);
    this.setModel(tableModel);
    this.setColumnModel(column_model);
  }
View Full Code Here

    // 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).
    public void packColumn(JTable table, int vColIndex, int margin) {
        TableModel model = table.getModel();
        DefaultTableColumnModel colModel = (DefaultTableColumnModel)table.getColumnModel();
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;
   
        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
View Full Code Here

    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);
  }
View Full Code Here

      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();
   }
View Full Code Here

   private void initScaleTable(DataScale[] scales, List<Object[]> rows, ColumnDisplayDefinition[] columnDefinitions)
   {
      DataScaleTableModel dataScaleTableModel = new DataScaleTableModel(scales);
      DataScaleTable dataScaleTable = new DataScaleTable(dataScaleTableModel, rows, columnDefinitions);

      TableColumnModel tcm = new DefaultTableColumnModel();
      dataScaleTable.setColumnModel(tcm);

      for (int i = 0; i < DataScaleTableModel.getColumnNames().length; i++)
      {
         TableColumn col = new TableColumn(i);
         col.setHeaderValue(DataScaleTableModel.getColumnNames()[i]);
         if (DataScaleTableModel.COL_NAME_COLUMN.equals(DataScaleTableModel.getColumnNames()[i]))
         {
            col.setPreferredWidth(dataScaleTableModel.getColumnWidthForColName(DataScaleTableModel.COL_NAME_COLUMN));
         }
         else if (DataScaleTableModel.COL_NAME_DATA.equals(DataScaleTableModel.getColumnNames()[i]))
         {
            col.setPreferredWidth(dataScaleTableModel.getColumnWidthForColName(DataScaleTableModel.COL_NAME_DATA));
         }
         tcm.addColumn(col);
      }

      _overviewHolder.setOverview(dataScaleTable);
      initGui();
View Full Code Here


    private TableColumnModel createColumnModel(ColumnDisplayDefinition[] colDefs)
    {
      //_colDefs = hdgs;
      TableColumnModel cm = new DefaultTableColumnModel();

      _rntc = new RowNumberTableColumn();

      for (int i = 0; i < colDefs.length; ++i)
      {
        ColumnDisplayDefinition colDef = colDefs[i];
        int colWidth = colDef.getDisplayWidth() * _multiplier;
        if (colWidth > MAX_COLUMN_WIDTH * _multiplier)
        {
          colWidth = MAX_COLUMN_WIDTH * _multiplier;
        }
        else if (colWidth < MIN_COLUMN_WIDTH * _multiplier)
        {
            colWidth = MIN_COLUMN_WIDTH * _multiplier;
        }

        ExtTableColumn col = new ExtTableColumn(i, colWidth,
          CellComponentFactory.getTableCellRenderer(colDefs[i]), null);

            String headerValue;
            if (DataTypeGeneral.isUseColumnLabelInsteadColumnName())
            {
               headerValue = colDef.getLabel();
            }
            else
            {
               headerValue = colDef.getColumnName();
            }
           
            col.setHeaderValue(headerValue);
        col.setColumnDisplayDefinition(colDef);
        cm.addColumn(col);
      }

      return cm;
    }
View Full Code Here

   * Prints this component to make it fill <code>pageFormat</code> imageable size.
   */
  public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    // Create a printable column model from the column model of this table
    // with printable renderers for each column
    DefaultTableColumnModel printableColumnModel = new DefaultTableColumnModel();
    TableColumnModel columnModel = getColumnModel();
    final DefaultTableCellRenderer defaultRenderer = new DefaultTableCellRenderer();
    defaultRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
    TableCellRenderer printableHeaderRenderer = new TableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value,
                                   boolean isSelected, boolean hasFocus, int row, int column) {
          // Delegate rendering to default cell renderer
          JLabel headerRendererLabel = (JLabel)defaultRenderer.getTableCellRendererComponent(table, value,
              isSelected, hasFocus, row, column);
          // Don't display sort icon
          headerRendererLabel.setIcon(null);
          // Change header background and foreground
          headerRendererLabel.setBackground(Color.LIGHT_GRAY);
          headerRendererLabel.setForeground(Color.BLACK);
          headerRendererLabel.setBorder(BorderFactory.createCompoundBorder(
              BorderFactory.createLineBorder(Color.BLACK),
              headerRendererLabel.getBorder()));
          return headerRendererLabel;
        }
      };
    for (int columnIndex = 0, n = columnModel.getColumnCount(); columnIndex < n; columnIndex++) {
      final TableColumn tableColumn = columnModel.getColumn(columnIndex);
      // Create a printable column from existing table column
      TableColumn printableColumn = new TableColumn();
      printableColumn.setIdentifier(tableColumn.getIdentifier());
      printableColumn.setHeaderValue(tableColumn.getHeaderValue());
      TableCellRenderer printableCellRenderer = new TableCellRenderer() {
          public Component getTableCellRendererComponent(JTable table, Object value,
                                 boolean isSelected, boolean hasFocus, int row, int column) {
            // Delegate rendering to existing cell renderer
            TableCellRenderer cellRenderer = tableColumn.getCellRenderer();
            Component rendererComponent = cellRenderer.getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
            if (rendererComponent instanceof JCheckBox) {
              // Prefer a x sign for boolean values instead of check boxes
              rendererComponent = defaultRenderer.getTableCellRendererComponent(table,
                  ((JCheckBox)rendererComponent).isSelected() ? "x" : "", false, false, row, column);
            }
            rendererComponent.setBackground(Color.WHITE);
            rendererComponent.setForeground(Color.BLACK);
            return rendererComponent;
          }
        };
      // Change printable column cell renderer
      printableColumn.setCellRenderer(printableCellRenderer);
      // Change printable column header renderer
      printableColumn.setHeaderRenderer(printableHeaderRenderer);
      printableColumnModel.addColumn(printableColumn);
    }   
    return print(g, pageFormat, pageIndex, printableColumnModel, Color.BLACK);
  }
View Full Code Here

                        public void columnRemoved(TableColumnModelEvent e) {
                            // nothing to do
                        }

                        public void columnMoved(TableColumnModelEvent e) {
                            DefaultTableColumnModel o = (DefaultTableColumnModel) e
                                    .getSource();
                            TableColumn tc = o.getColumn(e.getFromIndex());
                            ColumnKeeper ck = ((ColumnKeeper) mapTableColumnColumnKeeper
                                    .get(tc));
                            if (ck != null)
                                ck.setInitIndex(e.getToIndex());
                            if (Mediator.getGanttProjectSingleton() != null)
View Full Code Here

    public static void autoAdjustColWidths(JTable table)
    {
        int i, j, h;
        for (i=0; i<table.getColumnCount(); i++)
        {
            DefaultTableColumnModel colModel = (DefaultTableColumnModel)table.getColumnModel();
            TableColumn col = colModel.getColumn(i);
            int width = 4;
            TableCellRenderer renderer = col.getHeaderRenderer();
            if (renderer == null)
                renderer = table.getTableHeader().getDefaultRenderer();
            Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, i);
View Full Code Here

TOP

Related Classes of javax.swing.table.DefaultTableColumnModel

Copyright © 2018 www.massapicom. 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.