configure JTable Row Height - Java Swing

Java examples for Swing:JTable Row

Description

configure JTable Row Height

Demo Code


//package com.java2s;
import java.awt.Font;
import java.awt.FontMetrics;

import javax.swing.JTable;
import javax.swing.UIManager;

public class Main {
    public static void configureRowHeight(JTable table) {
        int height = table.getRowHeight();
        Font cellFont = UIManager.getFont("TextField.font");
        if (cellFont != null) {
            FontMetrics metrics = table.getFontMetrics(cellFont);
            if (metrics != null) {
                height = metrics.getHeight() + 2;
            }//from   w  w  w. ja  va  2s.  com
        }
        table.setRowHeight(Math.max(table.getRowHeight(), height));
    }
}

Related Tutorials