1 package org.netbeans.modules.welcome.ui; 2 3 import java.awt.Component ; 4 import java.awt.Dimension ; 5 import javax.swing.JComponent ; 6 import javax.swing.JScrollPane ; 7 import org.netbeans.modules.welcome.content.Constants; 8 import org.openide.windows.TopComponent; 9 10 class RelativeSizeScrollPane extends JScrollPane implements Constants{ 11 12 private float relativeHeight; 13 private int minHeight; 14 15 public RelativeSizeScrollPane( JComponent c, float relativeHeight, int minHeight ) { 16 super( c ); 17 this.relativeHeight = relativeHeight; 18 this.minHeight = minHeight; 19 } 20 21 public Dimension getPreferredSize() { 22 Dimension retValue = super.getPreferredSize(); 23 24 Component 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 |