Here you can find the source of getComponentHeight(JComponent component)
static private int getComponentHeight(JComponent component)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import javax.swing.JComponent; public class Main { static private int getComponentHeight(JComponent component) { int height = component.getHeight(); return (height > 0 ? height : component.getPreferredSize().height); }// w w w . j a v a 2 s .com }