Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 98
Registered: ‎03-10-2011
My Device: 9700 Bold

Vertical Scroll

Hi, 

 

I have an application which utilises the vertical scroll to list 20 buttons one below each other. The problem I have is that there is a lot of un used space after the final button. How do I go about setting a limit for the vertical scroll so it stops at the end of the final button.

 

Thanks


Ash

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vertical Scroll

It sounds like you have have a nested collection of Managers and at least one of them is confused about the space it should take up, probably because you have defined it with USE_ALL_HEIGHT, or overridden sublayout(..) in some way so that its vertical extent is larger than it needs to be when displaying the contained Fields. 

 

So review all the Managers used in the application.

 

I think you will find this useful:

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

Regular Contributor
Posts: 98
Registered: ‎03-10-2011
My Device: 9700 Bold

Re: Vertical Scroll

Hi, 

 

I've read the article you suggested and it is true I have made use of the USE_ALL_HEIGHT function. How do I go about correcting this. This is my code below:

 

 

 public void createAndDisplayPremiership(){
 MainScreen newScreen1 = new MainScreen(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR);
 VerticalFieldManager backgroundManager = new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.USE_ALL_HEIGHT)
 {
 Bitmap logoBitmap2 = Bitmap.getBitmapResource("football_mm.png");
 int imgWidth = logoBitmap2.getWidth();
 int imgHeight = logoBitmap2.getHeight();
 int imgXPos = 5;
 int imgYPos = 17;
 int imgTop = 0, imgLeft = 0;
 public void paint(Graphics graphics)
 {
 graphics.setBackgroundColor(Color.PALEGREEN);
 graphics.clear();
 graphics.setColor(Color.FORESTGREEN);
 graphics.fillRect(0, 0, 480, 80);
 graphics.fillRect(0,0, 20, 940);
 graphics.fillRect(460, 0, 20, 940);
 graphics.fillRect(0, 940, 480, 20);
 imgXPos = 5;
 graphics.drawBitmap(45, imgYPos, imgWidth, imgHeight, logoBitmap2, imgLeft, imgTop);
 imgXPos = 385;
 graphics.drawBitmap(imgXPos, imgYPos, imgWidth, imgHeight, logoBitmap2, imgLeft, imgTop);
 super.paint(graphics);
 
 };
LabelField labelField = new LabelField();
backgroundManager.add(labelField =  new LabelField("Premiership", Field.FIELD_HCENTER)
{
protected void paint(Graphics g) {
 int prevColor = g.getColor();
 g.setColor(Color.WHITE);
 super.paint(g);
 g.setColor(prevColor);
}
});
Font myFont = Font.getDefault().derive(Font.BOLD | Font.ITALIC, 11, Ui.UNITS_pt);
labelField.setFont(myFont);
labelField.setMargin(20,20,20,20);
FixedWidthButtonField team1 = new FixedWidthButtonField("Arsenal", (Display.getWidth() / 2) - 30);
team1.setMargin(0,0,-4,0);
backgroundManager.add(team1);
FixedWidthButtonField team2 = new FixedWidthButtonField("Aston Villa", (Display.getWidth() / 2) - 30);
team2.setMargin(-4,0,-4,0);
backgroundManager.add(team2);
FixedWidthButtonField team3 = new FixedWidthButtonField("Birmingham", (Display.getWidth() / 2) - 30);
team3.setMargin(-4,0,-4,0);
backgroundManager.add(team3);
FixedWidthButtonField team4 = new FixedWidthButtonField("Blackburn", (Display.getWidth() / 2) - 30);
team4.setMargin(-4,0,-4,0);
backgroundManager.add(team4);
FixedWidthButtonField team5 = new FixedWidthButtonField("Blackpool", (Display.getWidth() / 2) - 30);
team5.setMargin(-4,0,-4,0);
backgroundManager.add(team5);
FixedWidthButtonField team6 = new FixedWidthButtonField("Bolton", (Display.getWidth() / 2) - 30);
team6.setMargin(-4,0,-4,0);
backgroundManager.add(team6);
FixedWidthButtonField team7 = new FixedWidthButtonField("Chelsea", (Display.getWidth() / 2) - 30);
team7.setMargin(-4,0,-4,0);
backgroundManager.add(team7);
FixedWidthButtonField team8 = new FixedWidthButtonField("Everton", (Display.getWidth() / 2) - 30);
team8.setMargin(-4,0,-4,0);
backgroundManager.add(team8);
FixedWidthButtonField team9 = new FixedWidthButtonField("Fulham", (Display.getWidth() / 2) - 30);
team9.setMargin(-4,0,-4,0);
backgroundManager.add(team9);
FixedWidthButtonField team10 = new FixedWidthButtonField("Liverpool", (Display.getWidth() / 2) - 30);
team10.setMargin(-4,0,-4,0);
backgroundManager.add(team10);
FixedWidthButtonField team11 = new FixedWidthButtonField("Manchester City", (Display.getWidth() / 2) - 30);
team11.setMargin(-4,0,-4,0);
backgroundManager.add(team11);
FixedWidthButtonField team12 = new FixedWidthButtonField("Manchester United", (Display.getWidth() / 2) - 30);
team12.setMargin(-4,0,-4,0);
backgroundManager.add(team12);
FixedWidthButtonField team13 = new FixedWidthButtonField("Newcastle", (Display.getWidth() / 2) - 30);
team13.setMargin(-4,0,-4,0);
backgroundManager.add(team13);
FixedWidthButtonField team14 = new FixedWidthButtonField("Stoke", (Display.getWidth() / 2) - 30);
team14.setMargin(-4,0,-4,0);
backgroundManager.add(team14);
FixedWidthButtonField team15 = new FixedWidthButtonField("Sunderland", (Display.getWidth() / 2) - 30);
team15.setMargin(-4,0,-4,0);
backgroundManager.add(team15);
FixedWidthButtonField team16 = new FixedWidthButtonField("Tottenham", (Display.getWidth() / 2) - 30);
team16.setMargin(-4,0,-4,0);
backgroundManager.add(team16);
FixedWidthButtonField team17 = new FixedWidthButtonField("West Brom", (Display.getWidth() / 2) - 30);
team17.setMargin(-4,0,-4,0);
backgroundManager.add(team17);
FixedWidthButtonField team18 = new FixedWidthButtonField("West Ham", (Display.getWidth() / 2) - 30);
team18.setMargin(-4,0,-4,0);
backgroundManager.add(team18);
FixedWidthButtonField team19 = new FixedWidthButtonField("Wigan", (Display.getWidth() / 2) - 30);
team19.setMargin(-4,0,-4,0);
backgroundManager.add(team19);
FixedWidthButtonField team20 = new FixedWidthButtonField("Wolves", (Display.getWidth() / 2) - 30);
team20.setMargin(-4,0,0,0);
backgroundManager.add(team20);
newScreen1.add(backgroundManager);
UiApplication.getUiApplication().pushScreen(newScreen1);
}

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vertical Scroll

I hope that the KB article actually explains this.  Review it again and look carefully at your use of Style, especially for the MainScreen. 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Vertical Scroll

Towards the end of the article Peter mentioned (I'm glad you find it useful, by the way Smiley Wink), there is a reference to the article explaining how to create custom backgrounds. The reference also asks you to review comments in that other ("background") article. Please do so - if you read thoroughly, you will figure it out by yourself. Judging by the level of your code, you shouldn't have much trouble doing so.

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Regular Contributor
Posts: 98
Registered: ‎03-10-2011
My Device: 9700 Bold

Re: Vertical Scroll

Hi,

 

I edited these lines of the code to end up with this :

 

 

MainScreen newScreen1 = new MainScreen(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
 VerticalFieldManager backgroundManager = new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR)

 

 

Now when I scroll the screen ends after the final button. However one of the shaded rectangles I have drawn to act as the bottom edge border is not visable.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vertical Scroll

That sounds like a layout problem with that specific button rather than an issue with the Manager.  I suggest you raise this as a separate problem.  I think we will need to see some code too. 

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Vertical Scroll

[ Edited ]

This (losing the last of the rectangles in the background) is indeed a separate issue. The solution to it will certainly include setVirtualExtent on your inner Manager inside its sublayout.  Try looking at those, then, if you are still unsuccessful, start a new topic.

 

[Edit]: Are definitely on the right track with your style bits usage.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!