Package javax.swing.table

Examples of javax.swing.table.TableColumn


  private void updateTableColumnsWidth() {
    int intercellWidth = getIntercellSpacing().width;
    TableColumnModel columnModel = getColumnModel();
    TableModel tableModel = getModel();
    for (int columnIndex = 0, n = columnModel.getColumnCount(); columnIndex < n; columnIndex++) {
      TableColumn column = columnModel.getColumn(columnIndex);
      int modelColumnIndex = convertColumnIndexToModel(columnIndex);
      int preferredWidth = column.getPreferredWidth();
      preferredWidth = Math.max(preferredWidth, column.getHeaderRenderer().getTableCellRendererComponent(
          this, column.getHeaderValue(), false, false, -1, columnIndex).getPreferredSize().width);
      for (int rowIndex = 0, m = tableModel.getRowCount(); rowIndex < m; rowIndex++) {
        preferredWidth = Math.max(preferredWidth,
            column.getCellRenderer().getTableCellRendererComponent(
                this, tableModel.getValueAt(rowIndex, modelColumnIndex), false, false, -1, columnIndex).
                    getPreferredSize().width);
      }
      column.setPreferredWidth(preferredWidth + intercellWidth);
      column.setWidth(preferredWidth + intercellWidth);
    }
  }
View Full Code Here


        // Create the list of custom columns
      TableCellRenderer headerRenderer = getHeaderRenderer();
      for (String columnProperty : preferences.getEditedProperties()) {
        if (columnProperty != "MODEL_ROTATION"
            && columnProperty != "MODEL") {
          TableColumn tableColumn = new TableColumn();
          tableColumn.setIdentifier(columnProperty);
          tableColumn.setHeaderValue(getColumnName(columnProperty, preferences));
          tableColumn.setPreferredWidth(getColumnPreferredWidth(columnProperty));
          tableColumn.setCellRenderer(getColumnRenderer(columnProperty, furnitureLibrary, preferences, controller));
          tableColumn.setHeaderRenderer(headerRenderer);
          addColumn(tableColumn);
        }
      }
    }
View Full Code Here

        if (furnitureTableColumnModel == null) {
          preferences.removePropertyChangeListener(UserPreferences.Property.LANGUAGE, this);
        } else {         
          // Change column name and renderer from current locale
          for (int i = 0; i < furnitureTableColumnModel.getColumnCount(); i++) {
            TableColumn tableColumn = furnitureTableColumnModel.getColumn(i);
            Object columnIdentifier = tableColumn.getIdentifier();
            if (columnIdentifier instanceof String) {
              try {
                tableColumn.setHeaderValue(furnitureTableColumnModel.getColumnName(
                    (String)columnIdentifier, preferences));
              } catch (IllegalArgumentException ex) {
                // Don't change unknown columns
              }
            }
View Full Code Here

      for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
        total += percentages[i];
      }
     
      for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
        TableColumn column = getColumnModel().getColumn(i);
        double width = tableDim.width * (percentages[i] / total);
        column.setPreferredWidth((int) width);
      }
    }
View Full Code Here

      properties.setValueAt(entry.getValue(), i, 1);
    }

    final JTable table = new JTable(properties);
    final TableColumnModel model = table.getColumnModel();
    TableColumn column = model.getColumn(0);
    column.setPreferredWidth(200);
    column = model.getColumn(1);
    column.setPreferredWidth(350);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    return table;

  }
View Full Code Here

    public void ignoreEdit(boolean b) {
        ignoreEdit = b;
    }

    private void applyColumnWidths() {
        TableColumn column;
        for (Enumeration<TableColumn> e = getColumnModel().getColumns(); e.hasMoreElements();) {
            column = e.nextElement();
            if (!columnsHidden.contains(column) && column.getIdentifier() instanceof Integer)
                column.setPreferredWidth(getPreferredWidth((Integer) column.getIdentifier()));
        }
    }
View Full Code Here

    }
   
    public void applyHeaders() {
        DcTableHeaderRenderer.getInstance().applySettings();

        TableColumn column;
        for (Enumeration<TableColumn> e = getColumnModel().getColumns(); e.hasMoreElements();) {
            column = e.nextElement();
            column.setHeaderRenderer(DcTableHeaderRenderer.getInstance());
            columns.put(column.getIdentifier(), column);
        }
    }
View Full Code Here

    public void removeFields(int[] fields) {
        cancelEdit();

        int columnIndex;
        int tableIndex;
        TableColumn column;
        for (int i = 0; i < fields.length; i++) {
            columnIndex = getColumnIndexForField(fields[i]);
            tableIndex = convertColumnIndexToView(columnIndex);
            try {
                column = getColumnModel().getColumn(tableIndex);
View Full Code Here

            try {
                // media module does not have all columns available for specialized objects. Skip if the
                // column is not available.
                if (module != null && module.isAbstract() && !columns.containsKey(indices[i])) continue;

                TableColumn column = columns.get(indices[i]);
                int col = column.getModelIndex();

                Object newValue = dco.getValue(indices[i]);

                if (newValue instanceof Picture)
                    newValue = ((Picture) newValue).isDeleted() ? null : newValue;
               
                getDcModel().setValueAt(newValue, row, col);

            } catch (Exception e) {
                Integer key = indices[i];
                TableColumn column = columns.containsKey(key) ? columns.get(key) : null;
                logger.error("Error while setting value for column " + column + " module: " + module, e);
            }
        }

        if (module.isAbstract()) {
View Full Code Here

        DcObject dco = module.getItem();
        getDcModel().setColumnCount(dco.getFields().size());

        int counter = 0;
        for (DcField field : dco.getFields()) {
            TableColumn columnNew = getColumnModel().getColumn(counter);
            columnNew.setIdentifier(field.getIndex());
            columnNew.setHeaderValue(field.getLabel());

            columnNew.setPreferredWidth(getPreferredWidth(field.getIndex()));
           
            if (       field.getIndex() == DcObject._ID
                    || field.getIndex() == DcObject._SYS_LENDBY
                    || field.getIndex() == DcObject._SYS_LOANDURATION
                    || field.getIndex() == DcObject._SYS_CREATED
                    || field.getIndex() == DcObject._SYS_MODIFIED) {

                DcShortTextField text = ComponentFactory.getTextFieldDisabled();
                columnNew.setCellEditor(new DefaultCellEditor(text));
                DcTableCellRenderer renderer = DcTableCellRenderer.getInstance();
                renderer.setFont(ComponentFactory.getSystemFont());
                columnNew.setCellRenderer(renderer);
            } else if (field.getFieldType() == ComponentFactory._REFERENCESFIELD) {
                columnNew.setCellEditor(new DefaultCellEditor(ComponentFactory.getTextFieldDisabled()));
                columnNew.setCellRenderer(ReferencesTableCellRenderer.getInstance());
            } else if (field.getIndex() == DcObject._SYS_MODULE) {
                DcShortTextField text = ComponentFactory.getTextFieldDisabled();
                columnNew.setCellEditor(new DefaultCellEditor(text));
                columnNew.setCellRenderer(ModuleTableCellRenderer.getInstance());
            } else if (dco.getModule().getIndex() == DcModules._LOAN &&
                       field.getIndex() == Loan._C_CONTACTPERSONID) {
                DcShortTextField text = ComponentFactory.getTextFieldDisabled();
                columnNew.setCellEditor(new DefaultCellEditor(text));
                columnNew.setCellRenderer(ContactPersonTableCellRenderer.getInstance());
            } else {
                switch (field.getFieldType()) {
                case ComponentFactory._DATEFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor(ComponentFactory.getTextFieldDisabled()));
                    columnNew.setCellRenderer(DateFieldCellRenderer.getInstance());
                    break;
                case ComponentFactory._AVAILABILITYCOMBO:
                    columnNew.setCellEditor(new DefaultCellEditor(ComponentFactory.getTextFieldDisabled()));
                    columnNew.setCellRenderer(AvailabilityCheckBoxTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._CHECKBOX:
                    columnNew.setCellEditor(new DefaultCellEditor(ComponentFactory.getTextFieldDisabled()));
                    columnNew.setCellRenderer(CheckBoxTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._FILESIZEFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor((JTextField) getEditor(field)));
                    columnNew.setCellRenderer(FileSizeTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._NUMBERFIELD:
                case ComponentFactory._DECIMALFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor((JTextField) getEditor(field)));
                    columnNew.setCellRenderer(NumberTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._LONGTEXTFIELD:
                case ComponentFactory._SHORTTEXTFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor((JTextField) getEditor(field)));
                    break;
                case ComponentFactory._TIMEFIELD:
                    DcNumberField numberField = ComponentFactory.getNumberField();
                    columnNew.setCellEditor(new DefaultCellEditor(numberField));
                    columnNew.setCellRenderer(TimeFieldTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._URLFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor((JTextField) getEditor(field)));
                    DcTableCellRenderer renderer = DcTableCellRenderer.getInstance();
                    renderer.setForeground(new Color(0, 0, 255));
                    columnNew.setCellRenderer(renderer);
                    break;
                case ComponentFactory._PICTUREFIELD:
                    DcShortTextField text = ComponentFactory.getTextFieldDisabled();
                    text.setEditable(false);
                    text.setFont(ComponentFactory.getUnreadableFont());
                    columnNew.setCellEditor(new DefaultCellEditor(text));
                    columnNew.setCellRenderer(PictureTableCellRenderer.getInstance());
                    break;
                case ComponentFactory._REFERENCEFIELD:
                    columnNew.setCellRenderer(ComboBoxTableCellRenderer.getInstance());
                    columnNew.setCellEditor(new DefaultCellEditor((JComboBox) getEditor(field)));
                    break;
                case ComponentFactory._RATINGCOMBOBOX:
                    columnNew.setCellRenderer(RatingTableCellRenderer.getInstance());
                    columnNew.setCellEditor(new DefaultCellEditor((DcRatingComboBox) getEditor(field)));
                    break;
                case ComponentFactory._YESNOCOMBO:
                    columnNew.setCellEditor(new DefaultCellEditor((JComboBox) getEditor(field)));
                    break;
                case ComponentFactory._LOGINNAMEFIELD:
                    columnNew.setCellEditor(new DefaultCellEditor((DcLoginNameField) getEditor(field)));
                    break;
                }
            }
            counter++;
        }
View Full Code Here

TOP

Related Classes of javax.swing.table.TableColumn

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.