KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > welcome > ui > RelativeSizeScrollPane


1 package org.netbeans.modules.welcome.ui;
2
3 import java.awt.Component JavaDoc;
4 import java.awt.Dimension JavaDoc;
5 import javax.swing.JComponent JavaDoc;
6 import javax.swing.JScrollPane JavaDoc;
7 import org.netbeans.modules.welcome.content.Constants;
8 import org.openide.windows.TopComponent;
9
10 class RelativeSizeScrollPane extends JScrollPane JavaDoc implements Constants{
11
12     private float relativeHeight;
13     private int minHeight;
14
15     public RelativeSizeScrollPane( JComponent JavaDoc c, float relativeHeight, int minHeight ) {
16         super( c );
17         this.relativeHeight = relativeHeight;
18         this.minHeight = minHeight;
19     }
20
21     public Dimension JavaDoc getPreferredSize() {
22         Dimension JavaDoc retValue = super.getPreferredSize();
23         
24         Component JavaDoc parent = getParent();
25         while (null != parent) {
26             if (parent instanceof TopComponent) {
27                 retValue.height = (int) ((parent.getSize().height-GRAPHICS_TOTAL_VERTICAL_HEIGHT) * relativeHeight);
28                 if( retValue.height < minHeight )
29                     retValue.height = minHeight;
30             }
31             parent = parent.getParent();
32         }
33         return retValue;
34     }
35
36 }
Popular Tags