KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > FixedHeightJTable


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
20
21 import java.awt.Font JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import javax.swing.JTable JavaDoc;
24
25 /** JTables do not automatically scale their row height with font size, so when
26  * running under, for example --fontsize 16 (common for Chinese), the rows of our
27  * tables are too narrow and only marginally usable. For --fontsize 24, the text
28  * overlap makes the rows illegible.
29  *
30  * This code is take from a posting Tim Boudreau made on javalobby and automatically
31  * scales the row height with the font size or if the font is changed. It does not
32  * take icon height into account but we don't use icons anywhere.
33  *
34  * @author Peter Williams
35  */

36 public class FixedHeightJTable extends JTable JavaDoc {
37
38     private boolean firstPaint = true;
39
40     public void setFont (Font JavaDoc f) {
41         firstPaint = true;
42         super.setFont(f);
43     }
44
45     private void calcFixedHeight (Graphics JavaDoc g) {
46         g.setFont (getFont());
47         setRowHeight(g.getFontMetrics().getHeight());
48         firstPaint = false;
49     }
50
51     public void paint (Graphics JavaDoc g) {
52         if (firstPaint) {
53             calcFixedHeight(g);
54             //Setting the fixed height will generate another paint request,
55
//no need to complete this one
56
return;
57         }
58         super.paint (g);
59     }
60 }
61
Popular Tags