Wednesday, March 18, 2009

How to : display Horizontal and Vertical scrollbar with arrows

How To If you have few rows and few columns in your application. Number of columns and rows are more. In order to display next column or next row, we need to nevigate in respective direction (left , right, up ,down).

And if you want to show the scroll bars with ARROWS following code can help you :

for Horizontal Scrollbar arrows:

HorizontalFieldManager hfmScrollbar;
hfmScrollbar=new HorizontalFieldManager()
{
protected void sublayout(int maxwidth,int MaxHeight)
{
setExtent(FIELD_WIDTH,20);
}
public void paint(Graphics g)
{
g.setColor(Color.BLACK);
g.drawRect(0,0,FIELD_WIDTH,20);
int lxPts[] = {5, 15, 15};
int lyPts[] = {10,5,15};
int rxPts[] = {FIELD_WIDTH-5,FIELD_WIDTH-15,FIELD_WIDTH-15};
int ryPts[] = {10,5,15}; g.drawFilledPath(lxPts, lyPts, null, null); g.drawFilledPath(rxPts, ryPts, null, null);
super.paint(g);
}
};

for Vertical Scrollbar arrows :

VerticalFieldManager vfmScrollbar=new VerticalFieldManager(){
protected void sublayout(int maxWidth,int maxHeight){
setExtent(20,160);
}
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.drawRect(0,0,20,160);
int uxPts[]={5,10,15};
int uyPts[]={15,5,15};
int dxPts[]={5,10,15};
int dyPts[]={145,155,145};
if(currentRow>7)
g.drawFilledPath(uxPts, uyPts, null, null);
if(totalRows>8 && currentRow<totalRows)
g.drawFilledPath(dxPts, dyPts, null, null);
super.paint(g);
}
};

No comments:

Post a Comment

Place your comments here...