Example usage for javax.swing JTable setTableHeader

List of usage examples for javax.swing JTable setTableHeader

Introduction

In this page you can find the example usage for javax.swing JTable setTableHeader.

Prototype

@BeanProperty(description = "The JTableHeader instance which renders the column headers.")
public void setTableHeader(JTableHeader tableHeader) 

Source Link

Document

Sets the tableHeader working with this JTable to newHeader.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTable table = new JTable();
    // Remove the column headers
    table.setTableHeader(null);
}

From source file:MainClass.java

public static void main(String args[]) {
    Object rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    Object headers[] = { "Upper", "Lower" };
    JTable table = new JTable(rows, headers);
    table.setTableHeader(null);
    JScrollPane scrollPane = new JScrollPane(table);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);//from w w w . j a va 2  s .c o m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
            { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "Column 1", "Column 2", "Column 3" };

    JTable table = new JTable(rowData, columnNames);
    table.setTableHeader(null);
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setColumnHeaderView(null);
    JFrame frame = new JFrame();
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*w  ww  . ja  va  2s  . c o  m*/
    frame.setVisible(true);
}

From source file:HeaderlessSample.java

public static void main(String args[]) {
    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
            { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "Column 1", "Column 2", "Column 3" };
    //    JTable table = new HeaderlessTable(rowData, columnNames);
    JTable table = new JTable(rowData, columnNames);
    table.setTableHeader(null);
    JScrollPane scrollPane = new JScrollPane(table);
    //    scrollPane.setColumnHeaderView(null);
    JFrame frame = new JFrame("Headerless Table");
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);//from   w  w w .  j  a  va2 s.  c o m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
            { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "1", "2", "3" };
    JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    table.setTableHeader(null);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*from w  w w.j av  a 2  s  .  c  o  m*/
    frame.setVisible(true);

}

From source file:org.drugis.mtc.gui.results.ResultsComponentFactory.java

private static JTable createTableWithoutHeaders(NetworkRelativeEffectTableModel dm) {
    final JTable table = new JTable(dm);
    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (final TableColumn c : Collections.list(table.getColumnModel().getColumns())) {
        c.setMinWidth(170);//ww w  . ja  v  a2 s .co  m
        c.setPreferredWidth(170);
    }

    TableCopyHandler.registerCopyAction(table);
    return table;
}

From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java

/**
 * Make table of results (Cipriani et al., Lancet(2009), fig. 3, pp752).
 * @param mtc Model for which to display results.
 * @return A TablePanel//from w w  w  .  j a va 2s. co  m
 */
private TablePanel createNetworkTablePanel(final MTCModelWrapper<TreatmentDefinition> mtc) {
    NetworkRelativeEffectTableModel tableModel = NetworkRelativeEffectTableModel.build(d_pm.getAlternatives(),
            mtc);
    final JTable table = new JTable(tableModel);
    final NetworkRelativeEffectTableCellRenderer renderer = new NetworkRelativeEffectTableCellRenderer(
            !d_pm.isContinuous());
    table.setDefaultRenderer(Object.class, renderer);
    table.setTableHeader(null);

    table.addMouseListener(treatmentCategorizationListener(renderer));

    setColumnWidths(table);
    TableCopyHandler.registerCopyAction(table);
    return new TablePanel(table);
}

From source file:org.revager.tools.GUITools.java

/**
 * Creates a new standard table./*  ww  w.  ja v a  2 s  .co  m*/
 * 
 * @param model
 *            the table model
 * @param showHeader
 *            true if the header of the table should be visible
 * 
 * @return the newly created table
 */
@SuppressWarnings("serial")
public static JTable newStandardTable(TableModel model, boolean showHeader) {
    /*
     * Prep. for rollover
     */
    if (lastRolloverKey == Integer.MAX_VALUE) {
        lastRolloverKey = 0;
    } else {
        lastRolloverKey++;
    }

    final int keyIdx = lastRolloverKey;

    rollOverRowIndex.put(keyIdx, -1);

    final JTable table = new JTable(model) {

        @Override
        public boolean editCellAt(int row, int column, java.util.EventObject e) {
            boolean result = super.editCellAt(row, column, e);
            final Component editor = getEditorComponent();

            TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer();
            Font cellFont = null;
            if (renderer instanceof DefaultTableCellRenderer) {
                cellFont = ((DefaultTableCellRenderer) renderer).getFont();
            }
            if (editor != null && editor instanceof JTextComponent) {
                JTextComponent jTextComponent = (JTextComponent) editor;
                if (e == null) {
                    jTextComponent.selectAll();
                } else {
                    SwingUtilities.invokeLater(jTextComponent::selectAll);
                }
                jTextComponent.setBorder(UI.MARKED_BORDER_INLINE);
                if (cellFont != null) {
                    jTextComponent.setFont(cellFont);
                }
                editor.requestFocusInWindow();
            }
            return result;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TableCellRenderer renderer = super.getCellRenderer(row, column);
            if (renderer instanceof DefaultTableCellRenderer) {
                ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3));
            }
            return renderer;
        }

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            Component comp = super.prepareRenderer(renderer, row, col);
            // Rollover
            comp.setBackground(getBackground());
            comp = super.prepareRenderer(renderer, row, col);
            if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) {
                comp.setForeground(getForeground());
                comp.setBackground(UI.BLUE_BACKGROUND_COLOR);
            }

            // Tooltips
            JComponent jcomp = (JComponent) comp;
            if (renderer instanceof DefaultTableCellRenderer) {
                String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText();
                if (!StringUtils.isEmpty(toolTip)) {
                    jcomp.setToolTipText(toolTip);
                }
            }
            return comp;
        }
    };

    // Table properties
    table.setRowHeight(UI.TABLE_ROW_HEIGHT);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowGrid(false);
    table.setShowHorizontalLines(true);
    table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    // Rollover
    MouseInputAdapter rolloverListener = new MouseInputAdapter() {
        @Override
        public void mouseExited(MouseEvent e) {
            rollOverRowIndex.put(keyIdx, -1);
            table.repaint();
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            int row = table.rowAtPoint(e.getPoint());
            if (row != rollOverRowIndex.get(keyIdx)) {
                rollOverRowIndex.put(keyIdx, row);
                table.repaint();
            }
        }
    };
    table.addMouseMotionListener(rolloverListener);
    table.addMouseListener(rolloverListener);

    // Header
    if (!showHeader) {
        table.setTableHeader(null);
    }
    return table;
}