Java JTable Row Height getPreferredRowHeight(JTable table, int rowIndex, int margin)

Here you can find the source of getPreferredRowHeight(JTable table, int rowIndex, int margin)

Description

get Preferred Row Height

License

Apache License

Declaration

private static int getPreferredRowHeight(JTable table, int rowIndex, int margin) 

Method Source Code


//package com.java2s;
/*/*from   w  w w. ja  v a2  s  . c  om*/
   Copyright 2011 Udayakumar Dhansingh (Udy)
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
       
 */

import java.awt.Component;
import javax.swing.JTable;

import javax.swing.table.TableCellRenderer;

public class Main {
    private static int getPreferredRowHeight(JTable table, int rowIndex, int margin) {
        // Get the current default height for all rows
        int height = table.getRowHeight();

        // Determine highest cell in the row
        for (int c = 0; c < table.getColumnCount(); c++) {
            TableCellRenderer renderer = table.getCellRenderer(rowIndex, c);
            Component comp = table.prepareRenderer(renderer, rowIndex, c);
            int h = comp.getPreferredSize().height + 2 * margin;
            height = Math.max(height, h);
        }
        return height;
    }
}

Related

  1. correctRowHeight(JTable table)
  2. getRowBounds(JTable table, int row, int height)
  3. packRowHeights(final JTable table)
  4. platformTableRowHeight(JTable jtab, boolean forEdit)
  5. setRowHeight(JTable table, int row)