void (Component component, int rows, int columns) { final FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); final int width = fontMetrics.charWidth('m') * columns; component.setPreferredSize(new Dimension(width, fontMetrics.getHeight() * rows)); }