Example usage for javax.swing JTable setRowHeight

List of usage examples for javax.swing JTable setRowHeight

Introduction

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

Prototype

@BeanProperty(description = "The height in pixels of the cells in <code>row</code>")
public void setRowHeight(int row, int rowHeight) 

Source Link

Document

Sets the height for row to rowHeight, revalidates, and repaints.

Usage

From source file:Main.java

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

    DefaultTableModel model = new DefaultTableModel();
    model.setColumnIdentifiers(new Object[] { "Column 1", "Column 2", "Column 3" });

    JTable table = new JTable(model);
    for (int count = 0; count < 3; count++) {
        model.insertRow(count, new Object[] { count, "name", "age" });
    }/* ww  w.  j a  v a 2  s  .  c  o  m*/
    table.setRowHeight(1, 30);

    frame.add(new JScrollPane(table));
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Packs all table rows to their preferred height.
 *
 * @param table table to process/*from   ww w .j  a  v a2s  .c o  m*/
 */
public static void packRowHeights(final JTable table) {
    for (int row = 0; row < table.getRowCount(); row++) {
        int maxHeight = 0;
        for (int column = 0; column < table.getColumnCount(); column++) {
            final TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
            final Object valueAt = table.getValueAt(row, column);
            final Component renderer = cellRenderer.getTableCellRendererComponent(table, valueAt, false, false,
                    row, column);
            final int heightPreferable = renderer != null ? renderer.getPreferredSize().height : 0;
            maxHeight = Math.max(heightPreferable, maxHeight);
        }
        table.setRowHeight(row, maxHeight);
    }
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public static void packRows(JTable table, int start, int end, int margin) {
    for (int r = 0; r < table.getRowCount(); r++) {
        // Get the preferred height
        int h = getPreferredRowHeight(table, r, margin);

        // Now set the row height using the preferred height
        if (table.getRowHeight(r) != h) {
            table.setRowHeight(r, h);
        }//from   ww w. ja va 2s . co  m
    }
}

From source file:ca.uhn.hl7v2.testpanel.ui.ActivityDetailsCellRenderer.java

private void updatePreferredHeight(final JTable theTable, final int theRow) {
    final int newHeight = (int) getPreferredSize().getHeight();
    if (theTable.getRowHeight(theRow) != newHeight) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                theTable.setRowHeight(theRow, newHeight);
                //               theTable.getColumnModel().getColumn(2).setWidth(5000);
            }//  w w  w  .j a va 2s .  c o m
        });
    }
}

From source file:com.sander.verhagen.frame.LineWrapCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    String text = value.toString();
    setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
    int columnWidth = table.getColumnModel().getColumn(column).getWidth();
    setSize(columnWidth, 0 /* don't know yet */);
    setText(text);/*  ww  w  .  j a va2  s .  c o m*/

    int fontHeight = this.getFontMetrics(this.getFont()).getHeight();
    if (StringUtils.isEmpty(text)) {
        table.setRowHeight(row, fontHeight);
    } else {
        table.setRowHeight(row, fontHeight * getLineCount(this));
    }
    return this;
}

From source file:com.digitalgeneralists.assurance.ui.renderers.ComparisonResultListRenderer.java

public java.awt.Component getTableCellRendererComponent(JTable list, Object value, boolean isSelected,
        boolean cellHasFocus, int row, int column) {
    ComparisonResultPanel panel = new ComparisonResultPanel((ComparisonResult) value);

    if (isSelected) {
        panel.setBackground(list.getSelectionBackground());
        panel.setForeground(list.getSelectionForeground());
    } else {//from www  .  j a v a 2  s  . c o m
        if ((row % 2.0) == 0) {
            panel.setBackground(Color.white);
        } else {
            panel.setBackground(Color.lightGray);
        }
    }

    list.setRowHeight(row, ((panel.getNumberOfLines() * 18) + 70));

    return panel;
}

From source file:Main.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        setBackground(UIManager.getColor("Table.selectionBackground"));
    }/*from w  ww.  ja va  2s . co  m*/

    if (hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));

        if (table.isCellEditable(row, column)) {
            super.setForeground(UIManager.getColor("Table.focusCellForeground"));
            super.setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else {
        setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    }
    setText((String) (value));
    table.setRowHeight(row, getPreferredSize().height + row * 10);
    return this;
}

From source file:ca.uhn.hl7v2.testpanel.ui.ActivityDetailsCellRenderer.java

private void renderInfo(final JTable theTable, Object theValue, final int theRow) {
    if (theValue instanceof ActivityInfoError) {
        setForeground(Color.red);
    } else {/*from   w  w w  .j  a v a 2s  . c  om*/
        setForeground(Color.black);
    }

    String message = ((ActivityInfo) theValue).getMessage();
    setText(message);
    // setText(text);

    setFont(myVarWidthFont);

    if (theTable.getRowHeight(theRow) != theTable.getRowHeight()) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                theTable.setRowHeight(theRow, theTable.getRowHeight());
            }
        });
    }
}

From source file:com.digitalgeneralists.assurance.ui.renderers.ComparisonResultListRenderer.java

public java.awt.Component getTableCellEditorComponent(JTable list, Object value, boolean isSelected, int row,
        int column) {
    this.cancelCellEditing();

    this.activeResult = (ComparisonResult) value;

    this.setPanel(
            new ComparisonResultPanel(this.activeResult, this.applicationDelegate, ((this.activeResult != null)
                    && (this.activeResult.getResolution() == AssuranceResultResolution.UNRESOLVED))));

    if (isSelected) {
        // No need to set the background properties here since the editor panel instance
        // will be displayed.
    } else {//www . ja v  a 2  s  . co m
        if ((row % 2.0) == 0) {
            this.getPanel().setBackground(Color.white);
        } else {
            this.getPanel().setBackground(Color.lightGray);
        }
    }

    list.setRowHeight(row, ((this.getPanel().getNumberOfLines() * 18) + 70));

    return this.getPanel();
}

From source file:org.omegat.gui.align.AlignPanelController.java

private static void resizeRows(JTable table) {
    for (int row = 0; row < table.getRowCount(); row++) {
        int max = 0;
        for (int col = BeadTableModel.COL_SRC; col < table.getColumnCount(); col++) {
            int colWidth = table.getColumnModel().getColumn(col).getWidth();
            TableCellRenderer cellRenderer = table.getCellRenderer(row, col);
            Component c = table.prepareRenderer(cellRenderer, row, col);
            c.setBounds(0, 0, colWidth, Integer.MAX_VALUE);
            int height = c.getPreferredSize().height;
            max = Math.max(max, height);
        }//  w ww  .  ja  va2 s .c o  m
        table.setRowHeight(row, max);
    }
}