Java JTable Column installDelegatingColumn(TableColumn column, String label)

Here you can find the source of installDelegatingColumn(TableColumn column, String label)

Description

install Delegating Column

License

LGPL

Declaration

public static void installDelegatingColumn(TableColumn column, String label) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.EventObject;

import javax.swing.JButton;
import javax.swing.JComponent;

import javax.swing.JTable;
import javax.swing.event.CellEditorListener;

import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

public class Main {
    public static void installDelegatingColumn(TableColumn column, String label) {
        column.setMaxWidth(new JButton(label).getPreferredSize().width);
        column.setCellRenderer(new TableCellRenderer() {
            @Override/*from  w w  w. ja va 2s .c o  m*/
            public JComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                return (JComponent) value;
            }
        });
        column.setCellEditor(new TableCellEditor() {
            @Override
            public Object getCellEditorValue() {
                return null;
            }

            @Override
            public boolean isCellEditable(EventObject anEvent) {
                return true;
            }

            @Override
            public boolean shouldSelectCell(EventObject anEvent) {
                return false;
            }

            @Override
            public boolean stopCellEditing() {
                return true;
            }

            @Override
            public void cancelCellEditing() {
            }

            @Override
            public void addCellEditorListener(CellEditorListener l) {
            }

            @Override
            public void removeCellEditorListener(CellEditorListener l) {
            }

            @Override
            public JComponent getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                    int column) {
                return (JComponent) value;
            }
        });
    }
}

Related

  1. getMultiLineColumnNames(String[] ret)
  2. getRealColumnPos(int colPos, JTable table)
  3. getRenderedComponentAt(JTable table, int row, int column)
  4. getTableColumn(JTable table, int columnIndex)
  5. hideColumn(JTable table, int columnIndex)
  6. isColumnDefinitionChange(TableModelEvent e)
  7. isColumnSorted(JTable table, int column)
  8. isNotDuplicateKeyOfTable(String text, TableModel model, int column)
  9. layoutColumns(JTable p_Table, boolean p_OnlyVisibleRows)