Scrollable Panel Problem
/*
* ScrollableFlowPanel.java
*
* Created on November 24, 2006, 2:25 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/import java.awt.*;
import javax.swing.*;
publicclass ScrollableFlowPanelextends JPanelimplements Scrollable{
publicvoid setBounds(int x,int y,int width,int height ){
super.setBounds( x, y, getParent().getWidth(), height );
}
public Dimension getPreferredSize(){
returnnew Dimension( getWidth(), getPreferredHeight() );
}
public Dimension getPreferredScrollableViewportSize(){
return super.getPreferredSize();
}
publicint getScrollableUnitIncrement( Rectangle visibleRect,int orientation,int direction ){
int hundredth = ( orientation == SwingConstants.VERTICAL
? getParent().getHeight() : getParent().getWidth() ) / 100;
return ( hundredth == 0 ? 1 : hundredth );
}
publicint getScrollableBlockIncrement( Rectangle visibleRect,int orientation,int direction ){
return orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth();
}
publicboolean getScrollableTracksViewportWidth(){
returntrue;
}
publicboolean getScrollableTracksViewportHeight(){
returnfalse;
}
privateint getPreferredHeight(){
int rv = 0;
for (int k = 0, count = getComponentCount(); k < count; k++ ){
Component comp = getComponent( k );
Rectangle r = comp.getBounds();
int height = r.y + r.height;
if ( height > rv )
rv = height;
}
rv += ( (FlowLayout) getLayout() ).getVgap();
//System.out.println(rv);
return rv;
}
}
I got this scrollable flow panel code from somewhere else which enables me to actually add items inside the Panel and enable me to do the vertical scrolling. The code works fine and it's great.
But I encounter 1 problem. It uses flow panel and flow panel is always sort of like running all over according to the size and number of items on the display. I wish to fixed the items to become like row by column and I wanted to change this code to be compatible with SpringLayout. But not exactly sure how to change it? =(

