Java Code Examples for javax.swing.table.TableColumn#setHeaderValue()

The following examples show how to use javax.swing.table.TableColumn#setHeaderValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableCheckBoxColumn.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 7 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader header = (JTableHeader) e.getSource();
    JTable table = header.getTable();
    TableColumnModel columnModel = table.getColumnModel();
    int vci = columnModel.getColumnIndexAtX(e.getX());
    int mci = table.convertColumnIndexToModel(vci);
    if (mci == targetColumnIndex) {
        if (SwingUtilities.isLeftMouseButton(e)) {
            TableColumn column = columnModel.getColumn(vci);
            Object v = column.getHeaderValue();
            boolean b = Status.DESELECTED.equals(v);
            TableModel m = table.getModel();
            for (int i = 0; i < m.getRowCount(); i++) {
                m.setValueAt(b, i, mci);
            }
            column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
        } else if (SwingUtilities.isRightMouseButton(e)) {
            if (popupMenu != null) {
                popupMenu.show(table, e.getX(), 0);
            }
        }
    }
}
 
Example 2
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data = m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example 3
Source File: Utilities.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static TableColumn createTableColumn(int index, String headerValue, TableCellRenderer headerRenderer,
	boolean resizable)
{
	TableColumn column = new TableColumn(index);
	if (headerValue.startsWith("in_"))
	{
		column.setHeaderValue(LanguageBundle.getString(headerValue));
	}
	else
	{
		column.setHeaderValue(headerValue);
	}
	column.setHeaderRenderer(headerRenderer);
	if (!resizable)
	{
		column.sizeWidthToFit();
		column.setMaxWidth(column.getMaxWidth() + 10);
		column.setPreferredWidth(column.getPreferredWidth() + 10);
	}
	column.setResizable(resizable);
	return column;
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseClicked(MouseEvent e) {
  JTableHeader header = (JTableHeader) e.getComponent();
  JTable tbl = header.getTable();
  TableColumnModel columnModel = tbl.getColumnModel();
  TableModel m = tbl.getModel();
  int vci = columnModel.getColumnIndexAtX(e.getX());
  int mci = tbl.convertColumnIndexToModel(vci);
  if (mci == targetColumnIndex && m.getRowCount() > 0) {
    TableColumn column = columnModel.getColumn(vci);
    boolean b = column.getHeaderValue() == Status.DESELECTED;
    for (int i = 0; i < m.getRowCount(); i++) {
      m.setValueAt(b, i, mci);
    }
    column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
    // header.repaint();
  }
}
 
Example 5
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data =  m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example 6
Source File: RowNumberTable.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
public RowNumberTable(JTable table) {
	main = table;
	main.addPropertyChangeListener(this);

	setFocusable(false);
	setAutoCreateColumnsFromModel(false);
	setModel(main.getModel());
	setSelectionModel(main.getSelectionModel());

	TableColumn column = new TableColumn();
	column.setHeaderValue(" ");
	addColumn(column);
	column.setCellRenderer(new RowNumberRenderer());

	getColumnModel().getColumn(0).setPreferredWidth(50);
	setPreferredScrollableViewportSize(getPreferredSize());
}
 
Example 7
Source File: Utilities.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static TableColumn createTableColumn(int index, String headerValue, TableCellRenderer headerRenderer,
	boolean resizable)
{
	TableColumn column = new TableColumn(index);
	if (headerValue.startsWith("in_"))
	{
		column.setHeaderValue(LanguageBundle.getString(headerValue));
	}
	else
	{
		column.setHeaderValue(headerValue);
	}
	column.setHeaderRenderer(headerRenderer);
	if (!resizable)
	{
		column.sizeWidthToFit();
		column.setMaxWidth(column.getMaxWidth() + 10);
		column.setPreferredWidth(column.getPreferredWidth() + 10);
	}
	column.setResizable(resizable);
	return column;
}
 
Example 8
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseClicked(MouseEvent e) {
  JTableHeader header = (JTableHeader) e.getComponent();
  JTable tbl = header.getTable();
  TableColumnModel columnModel = tbl.getColumnModel();
  TableModel m = tbl.getModel();
  int vci = columnModel.getColumnIndexAtX(e.getX());
  int mci = tbl.convertColumnIndexToModel(vci);
  if (mci == targetColumnIndex && m.getRowCount() > 0) {
    TableColumn column = columnModel.getColumn(vci);
    boolean b = column.getHeaderValue() == Status.DESELECTED;
    for (int i = 0; i < m.getRowCount(); i++) {
      m.setValueAt(b, i, mci);
    }
    column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
    // header.repaint();
  }
}
 
Example 9
Source File: UpdateSummaryTable.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
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();
 }
 
Example 10
Source File: MTable.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * Ajoute une colonne dans la table.
 *
 * @param attribute
 *           Nom de l'attribut des objets à afficher dans la colonne<br/>
 * @param libelle
 *           Libellé à afficher en entête de la colonne
 * @return this (fluent)
 */
public MTable<T> addColumn(final String attribute, final String libelle) {
	final int modelIndex = getColumnCount();
	final TableColumn tableColumn = new TableColumn(modelIndex);
	// on met l'énumération de l'attribut comme identifier dans le TableColumn pour s'en servir dans MTableModel
	tableColumn.setIdentifier(attribute);
	if (libelle == null) {
		// on prend par défaut l'attribut si le libellé n'est pas précisé,
		tableColumn.setHeaderValue(attribute);
	} else {
		// le libellé a été précisé pour l'entête de cette colonne
		tableColumn.setHeaderValue(libelle);
	}
	// ajoute la colonne dans la table
	super.addColumn(tableColumn);
	return this;
}
 
Example 11
Source File: JTreeViewTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void setTreeView(TreeView<? super T> view)
{
	TableColumn viewColumn = getColumn(TREE_VIEW_COL_PREFS_KEY);
	treetableModel.setSelectedTreeView(view);
	viewColumn.setHeaderValue(view.getViewName());
	sortModel();
	getTableHeader().repaint();
	PropertyContext context = BASE_CONTEXT.createChildContext(this.viewModel.getDataView().getPrefsKey());

	int index = getIndex(viewModel.getTreeViews(), view);
	if (index >= 0)
	{
		context.setInt(VIEW_INDEX_PREFS_KEY, index);
	}
}
 
Example 12
Source File: TableCheckBoxColumn.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
        int mci = 0;
        int vci = table.convertColumnIndexToView(mci);
        TableColumn column = table.getColumnModel().getColumn(vci);
        Object title = column.getHeaderValue();
        if (!Status.INDETERMINATE.equals(title)) {
            column.setHeaderValue(Status.INDETERMINATE);
        } else {
            int selected = 0, deselected = 0;
            TableModel m = table.getModel();
            for (int i = 0; i < m.getRowCount(); i++) {
                if (Boolean.TRUE.equals(m.getValueAt(i, mci))) {
                    selected++;
                } else {
                    deselected++;
                }
            }
            if (selected == 0) {
                column.setHeaderValue(Status.DESELECTED);
            } else if (deselected == 0) {
                column.setHeaderValue(Status.SELECTED);
            } else {
                return;
            }
        }
        table.getTableHeader().repaint();
    }
}
 
Example 13
Source File: CounterRequestForContextTable.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void addCustomColumn(String headerValue, TableCellRenderer tableCellRenderer) {
	final TableColumn tableColumn = new TableColumn(getColumnCount());
	tableColumn.setIdentifier(getColumnCount());
	tableColumn.setHeaderValue(headerValue);
	tableColumn.setCellRenderer(tableCellRenderer);
	addColumn(tableColumn);
}
 
Example 14
Source File: JTreeViewTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void setTreeView(TreeView<? super T> view)
{
	TableColumn viewColumn = getColumn(TREE_VIEW_COL_PREFS_KEY);
	treetableModel.setSelectedTreeView(view);
	viewColumn.setHeaderValue(view.getViewName());
	sortModel();
	getTableHeader().repaint();
	PropertyContext context = BASE_CONTEXT.createChildContext(this.viewModel.getDataView().getPrefsKey());

	int index = getIndex(viewModel.getTreeViews(), view);
	if (index >= 0)
	{
		context.setInt(VIEW_INDEX_PREFS_KEY, index);
	}
}
 
Example 15
Source File: NamedIrSignal.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
private void setup() {
    for (int i = 0; i < columnFunc.noFields(); i++) {
        TableColumn column = new TableColumn(i, columnFunc.width(i));
        column.setHeaderValue(columnFunc.name(i));
        column.setIdentifier(i);
        addColumn(column);
    }
}
 
Example 16
Source File: CounterRequestDetailTablePanel.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private MTableScrollPane<CounterRequest> createScrollPane() {
	final MTable<CounterRequest> table = getTable();
	final MTableScrollPane<CounterRequest> tableScrollPane = new MTableScrollPane<>(table);

	table.addColumn("name", getString("Requete"));
	table.setColumnCellRenderer("name", new NameTableCellRenderer());
	if (!childRequestsExecutions.isEmpty()) {
		final TableColumn nbExecutionsColumn = new TableColumn(table.getColumnCount());
		nbExecutionsColumn.setIdentifier(table.getColumnCount());
		nbExecutionsColumn.setHeaderValue(getString("Hits_par_requete"));
		table.addColumn(nbExecutionsColumn);

		nbExecutionsColumn.setCellRenderer(new NbExecutionsTableCellRenderer());
	}
	table.addColumn("mean", getString("Temps_moyen"));
	table.addColumn("maximum", getString("Temps_max"));
	table.addColumn("standardDeviation", getString("Ecart_type"));
	table.addColumn("cpuTimeMean", getString("Temps_cpu_moyen"));
	table.addColumn("systemErrorPercentage", getString("erreur_systeme"));
	table.setColumnCellRenderer("cpuTimeMean", new MIntegerTableCellRenderer() {
		private static final long serialVersionUID = 1L;

		@Override
		public void setValue(Object value) {
			final Integer cpuTimeMean = (Integer) value;
			if (cpuTimeMean >= 0) {
				super.setValue(cpuTimeMean);
			} else {
				super.setValue(null);
			}
		}
	});

	final Counter parentCounter = getCounterByRequestId(request);
	final boolean allChildHitsDisplayed = parentCounter != null
			&& parentCounter.getChildCounterName() != null && request.hasChildHits();
	if (allChildHitsDisplayed) {
		final String childCounterName = parentCounter.getChildCounterName();
		table.addColumn("childHitsMean",
				getFormattedString("hits_fils_moyens", childCounterName));
		table.addColumn("childDurationsMean",
				getFormattedString("temps_fils_moyen", childCounterName));
		final ChildValueTableCellRenderer childValueTableCellRenderer = new ChildValueTableCellRenderer();
		table.setColumnCellRenderer("childHitsMean", childValueTableCellRenderer);
		table.setColumnCellRenderer("childDurationsMean", childValueTableCellRenderer);
	}

	return tableScrollPane;
}
 
Example 17
Source File: DataViewBuilders.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected void setupInstance(TableColumn instance) {
    super.setupInstance(instance);
    
    instance.setHeaderValue(headerValue);
}
 
Example 18
Source File: JXTableRowHeader.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public InternalTableColumnModel() {
    TableColumn col = new TableColumn(0, 75);
    col.setHeaderValue("#");
    addColumn(col);
}
 
Example 19
Source File: GraphicalRenderer.java    From jsqsh with Apache License 2.0 4 votes vote down vote up
public void mouseClicked (MouseEvent e) {

                TableColumnModel colModel = table.getColumnModel();
                int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
                int modelIndex = colModel.getColumn(columnModelIndex)
                        .getModelIndex();

                if (modelIndex < 0) {

                    return;
                }

                if (sortedColumn == modelIndex) {

                    isAscending = !isAscending;
                }
                else {

                    sortedColumn = modelIndex;
                    isAscending = true;
                }

                for (int i = 0; i < getColumnCount(); i++) {

                    TableColumn column = colModel.getColumn(i);
                    column.setHeaderValue(getColumnName(
                        column.getModelIndex()));
                }

                table.getTableHeader().repaint();

                ColumnDescription des = columns[modelIndex];
                
                Collections.sort(getDataVector(), 
                        new ColumnComparator(modelIndex,
                    isAscending,  des, nullRepresentation));
                
                table.tableChanged(new TableModelEvent(
                    SortableTableModel.this));
                table.repaint();
            }
 
Example 20
Source File: TraceTableModel.java    From pega-tracerviewer with Apache License 2.0 3 votes vote down vote up
@Override
protected TableColumnModel getTableColumnModel() {

    TableColumnModel tableColumnModel = new DefaultTableColumnModel();

    for (int i = 0; i < getColumnCount(); i++) {

        TableColumn tableColumn = new TableColumn(i);

        String text = getColumnName(i);

        tableColumn.setHeaderValue(text);

        TraceTableModelColumn ttmc = getColumn(i);

        TraceTableCellRenderer ttcr = new TraceTableCellRenderer();
        ttcr.setBorder(new EmptyBorder(1, 3, 1, 1));
        ttcr.setHorizontalAlignment(ttmc.getHorizontalAlignment());

        tableColumn.setCellRenderer(ttcr);

        int colWidth = ttmc.getPrefColumnWidth();
        tableColumn.setPreferredWidth(colWidth);
        // tableColumn.setMinWidth(colWidth);
        tableColumn.setWidth(colWidth);
        tableColumn.setResizable(true);

        tableColumnModel.addColumn(tableColumn);
    }

    return tableColumnModel;
}