Example usage for javax.swing.table TableColumn setHeaderValue

List of usage examples for javax.swing.table TableColumn setHeaderValue

Introduction

In this page you can find the example usage for javax.swing.table TableColumn setHeaderValue.

Prototype

@BeanProperty(description = "The text to be used by the header renderer.")
public void setHeaderValue(Object headerValue) 

Source Link

Document

Sets the Object whose string representation will be used as the value for the headerRenderer.

Usage

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

public void resetHeader() {
    TableColumnModel colModel = jTable.getColumnModel();
    int colsNumber = getColumnsInfo().length;
    int colsModel = colModel.getColumnCount() + fixedColumns;
    if (colsNumber == colsModel) {
        if (getSelectorColumn() != null) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JTable fixedJTable = (JTable) jTable.getClientProperty(CP_FIXED_TABLE);
                    if (fixedJTable != null) {
                        fixedJTable.getTableHeader().repaint();
                    } else {
                        jTable.getTableHeader().repaint();
                    }/* w ww.  jav  a 2  s.  c om*/
                }
            });
        }
        return;
    }
    if (colsNumber > colsModel) {
        int delta = colsNumber - colModel.getColumnCount();
        for (int i = 0; i < delta; i++) {
            colModel.addColumn(new TableColumn());
        }
    }
    for (int i = 0; i < colsNumber; i++) {
        TableColumn column = colModel.getColumn(i);
        column.setHeaderValue(getColumnsInfo()[i].getColumnHeader());
    }
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JTable fixedJTable = (JTable) jTable.getClientProperty(CP_FIXED_TABLE);
            if (fixedJTable != null) {
                fixedJTable.getTableHeader().repaint();
            }
            jTable.getTableHeader().repaint();
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

@Override
public void setColumnCaption(Column column, String caption) {
    checkNotNullArgument(column, "column must be non null");

    if (!Objects.equals(column.getCaption(), caption)) {
        column.setCaption(caption);//from ww  w .  j a v  a2  s .  c o m
    }
    TableColumn tableColumn = getColumn(column);

    // If column is not hidden by security
    if (tableColumn != null) {
        tableColumn.setHeaderValue(caption);
    }
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Substitutes headers - replaces a column name with another one
 *
 * @param prevHeaderName - Previous column header
 * @param newHeaderName  - New column header
 *///w w w  .j  a  v  a2 s. c o m
public void substituteHeaderNames(String prevHeaderName, String newHeaderName) {
    Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns();

    while (columns.hasMoreElements()) {
        TableColumn col = columns.nextElement();

        if (col.getHeaderValue().toString().equals(prevHeaderName)) {
            col.setHeaderValue(newHeaderName);
        }
    }

    spreadsheet.getTable().addNotify();
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Adds a column to the table with a specified name
 *
 * @param headerLabel - name of column to be added
 *///from   w w w. ja  v a 2 s . c  o m
public TableColumn addColumn(Object headerLabel, boolean required) {
    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();
    TableColumn newColumn = new TableColumn(spreadsheet.getTable().getModel().getColumnCount());
    newColumn.setHeaderValue(headerLabel);
    newColumn.setPreferredWidth(calcColWidths(headerLabel.toString()));
    newColumn.setHeaderRenderer(spreadsheet.columnRenderer);

    // add a cell editor (if available to the column)
    addCellEditor(newColumn);

    model.addToColumns(headerLabel.toString());
    model.addColumn(headerLabel.toString());

    spreadsheet.getTable().addColumn(newColumn);

    addFieldToRequiredCellRendererIfVisible(required, newColumn.getModelIndex());

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    if (spreadsheet.getTable().getRowCount() > 0) {
        spreadsheet.getTable().setValueAt(
                spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()), 0,
                spreadsheet.getTable().getColumnCount() - 1);
        copyColumnDownwards(0, spreadsheet.getTable().getColumnCount() - 1);
        spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString());
    }

    spreadsheet.getTable().addNotify();

    return newColumn;
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Add a column after the currently selected column
 *
 * @param headerLabel             - name of column to add.
 * @param fixedVal                - initial value to populate column with, if any.
 * @param currentlySelectedColumn - place in table to add the column after.
 *///w w w  .j  a va 2  s. c o  m
public TableColumn addColumnAfterPosition(Object headerLabel, String fixedVal, boolean required,
        int currentlySelectedColumn) {

    if (currentlySelectedColumn == -1) {
        currentlySelectedColumn = (spreadsheet.getTable().getSelectedColumn() == -1)
                ? (spreadsheet.getTable().getColumnCount() - 1)
                : spreadsheet.getTable().getSelectedColumn();
    }

    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();

    int columnCount = spreadsheet.getTable().getModel().getColumnCount();

    TableColumn col = new TableColumn(columnCount);
    col.setHeaderValue(headerLabel);
    col.setPreferredWidth(calcColWidths(headerLabel.toString()));
    col.setHeaderRenderer(spreadsheet.columnRenderer);

    addFieldToRequiredCellRendererIfVisible(required, columnCount);

    addCellEditor(col);

    model.addToColumns(headerLabel.toString());
    model.addColumn(col);

    spreadsheet.getTable().addColumn(col);

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    // now move the column into its correct position
    int stopValue = headerLabel.toString().equals("Unit")
            ? (spreadsheet.previouslyAddedCharacteristicPosition + 1)
            : (currentlySelectedColumn + 1);

    for (int i = spreadsheet.getTable().getColumnCount() - 1; i > stopValue; i--) {
        spreadsheet.getTable().getColumnModel().moveColumn(i - 1, i);
    }

    addDependentColumn(headerLabel, currentlySelectedColumn, col);

    if (headerLabel.toString().contains("Characteristics") || headerLabel.toString().contains("Factor")
            || headerLabel.toString().contains("Parameter")) {
        spreadsheet.previouslyAddedCharacteristicPosition = stopValue;
    }

    propagateDefaultValue(fixedVal, stopValue);

    spreadsheet.getTable().addNotify();

    return col;
}

From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java

public ExcelSheetView(ExcelSheet sheet, FlexoController controller) {
    super(new BorderLayout());
    this.sheet = sheet;
    this.controller = controller;
    tableModel = new ExcelSheetTableModel();
    table = new MultiSpanCellTable(tableModel);
    table.setBackground(Color.WHITE);
    table.setShowGrid(true);/*from   ww  w .  j av a2  s. co m*/
    table.setGridColor(Color.LIGHT_GRAY);
    table.setRowMargin(0);
    table.getColumnModel().setColumnMargin(0);

    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        TableColumn col = table.getColumnModel().getColumn(i);
        if (i == 0) {
            col.setWidth(25);
            col.setPreferredWidth(25);
            col.setMinWidth(25);
            col.setMaxWidth(100);
            // col.setResizable(false);
            col.setHeaderValue(null);
        } else {
            col.setWidth(sheet.getSheet().getColumnWidth(i - 1) / 40);
            col.setPreferredWidth(sheet.getSheet().getColumnWidth(i - 1) / 40);
            col.setHeaderValue("" + Character.toChars(i + 64)[0]);
        }
    }
    table.setDefaultRenderer(Object.class, new ExcelSheetCellRenderer());
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    add(new JScrollPane(table), BorderLayout.CENTER);

    cellIdentifier = new JTextField(6);
    cellIdentifier.setEditable(false);
    cellIdentifier.setHorizontalAlignment(SwingConstants.CENTER);
    cellValue = new JTextField();
    cellValue.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            valueEditedForSelectedCell(cellValue.getText());
        }
    });
    /*cellValue.getDocument().addDocumentListener(new DocumentListener() {
       @Override
       public void removeUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
            
       @Override
       public void insertUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
            
       @Override
       public void changedUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
    });*/
    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(cellIdentifier, BorderLayout.WEST);
    topPanel.add(cellValue, BorderLayout.CENTER);
    add(topPanel, BorderLayout.NORTH);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            selectionChanged();
        }
    });
    table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            selectionChanged();
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }
    });

    updateRowHeights();

    validate();

    /*for (Object p : sheet.getSheet().getWorkbook().getAllPictures()) {
       System.out.println("Picture: " + p);
    }
            
    System.out.println("class = " + sheet.getSheet().getClass());
            
    if (sheet.getSheet() instanceof HSSFSheet) {
            
       List<HSSFShape> shapes = ((HSSFSheet) sheet.getSheet()).getDrawingPatriarch().getChildren();
       System.out.println("Prout=" + shapes);
       for (int i = 0; i < shapes.size(); i++) {
    System.out.println("hop avec " + shapes.get(i));
    if (shapes.get(i) instanceof HSSFPicture) {
       HSSFPicture pic = (HSSFPicture) shapes.get(i);
       HSSFPictureData picdata = ((HSSFSheet) sheet.getSheet()).getWorkbook().getAllPictures().get(pic.getPictureIndex());
            
       System.out.println("New picture found : " + pic);
       System.out.println("Anchor : " + pic.getAnchor());
       System.out.println("file extension " + picdata.suggestFileExtension());
            
       // int pictureIndex = this.newSheet.getWorkbook().addPicture( picdata.getData(), picdata.getFormat());
            
       // this.newSheet.createDrawingPatriarch().createPicture((HSSFClientAnchor)pic.getAnchor()r, pictureIndex);
            
    }
            
       }
    }*/
}

From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java

public void addColumn(final TableColumn column) {
    stopEditing();/*from   w  w  w .j a  v a  2 s  . c o m*/
    if (column.getHeaderValue() == null) {
        final int modelColumn = column.getModelIndex();
        final String columnName = getModel().getColumnName(modelColumn);
        if (modelColumn == 0) {
            column.setResizable(false);
            column.setHeaderValue(columnName);
            column.setPreferredWidth(30);
            column.setMaxWidth(30);
            column.setMinWidth(30);
        } else {
            final Class columnType = getModel().getColumnClass(modelColumn);
            column.setHeaderValue(new TypedHeaderInformation(columnType, columnName));
        }
    }
    getColumnModel().addColumn(column);

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private void updateColumnModel() {
    TableColumnModel columnModel = table.getColumnModel();
    totalFlex = 0;/*from   w ww. j a v  a 2  s . c  o  m*/

    for (int i = 0; i < columns.getChildNodes().size(); i++) {
        if (i >= columnModel.getColumnCount()) {
            break;
        }

        SwingTreeCol child = (SwingTreeCol) columns.getChildNodes().get(i);
        TableColumn col = columnModel.getColumn(i);

        totalFlex += child.getFlex();

        col.setHeaderValue(child.getLabel());

        col.setCellEditor(getCellEditor(child));

        col.setCellRenderer(getCellRenderer(child));

        // List<XulComponent> cells = child.getChildNodes();
        // for(int z=0; z<cells.size(); z++){
        // XulComponent cell = cells.get(z);
        // }
    }
}

From source file:org.piraso.ui.api.StackTraceFilterDialog.java

private void initTable() {
    TableColumn regexColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldColumn = jtable.getColumnModel().getColumn(1);

    regexColumn.setHeaderValue("Regex");
    regexColumn.setPreferredWidth(210);//ww  w.  ja  v a2  s  .c om

    boldColumn.setHeaderValue("Bold");
    boldColumn.setPreferredWidth(30);
    boldColumn.setMaxWidth(30);
    boldColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    boldColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.api.WorkingSetDialog.java

private void initTable() {
    TableColumn regexColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldColumn = jtable.getColumnModel().getColumn(1);

    regexColumn.setHeaderValue("Name");
    regexColumn.setPreferredWidth(210);//from   w  ww . j  a  v a  2s  . c  om

    boldColumn.setHeaderValue("Regex");
    boldColumn.setPreferredWidth(210);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}