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
New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Hi Rab,

                  I tried ur code that is scrolling the contents with background by extending Screen, it Good thank u. But i have a slight problem here that is, When i try to add more contents i.e i added more buttons in the content manager and u executed and when I scroll down i found that buttons are present but the background is white that is the background image is not present its missing only he contents are there........ for more cearence i have made a slight modification u r code by adding few more buttons and sending kindly see the result and pls help to paint the back ground completely with the image.........  

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Hi Rab,

                  I tried ur code that is scrolling the contents with background by extending Screen, it Good thank u. But i have a slight problem here that is, When i try to add more contents i.e i added more buttons in the content manager and u executed and when I scroll down i found that buttons are present but the background is white that is the background image is not present its missing only he contents are there........ for more cearence i have made a slight modification u r code by adding few more buttons and sending kindly see the result and pls help to paint the back ground completely with the image.........  

 

 

import net.rim.device.api.io.MIMETypeAssociations; import net.rim.device.api.system.Characters; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; import net.rim.device.api.i18n.*; import java.io.*; import java.util.Vector; import net.rim.device.api.ui.UiApplication; import javax.microedition.io.*; import javax.microedition.io.file.*; public class TestScreen extends Screen{ private VerticalFieldManager contentManager; private HorizontalFieldManager headerManager; Bitmap img_Background = null; public TestScreen() { super(new VerticalFieldManager(),NO_VERTICAL_SCROLL); LabelField demoText = new LabelField("Hello World Demo", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); headerManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.setBackgroundColor(Color.YELLOW); graphics.clear(); super.paint(graphics); } }; headerManager.add(demoText); this.add(headerManager); img_Background = Bitmap.getBitmapResource("com.zylog/res/images/BlueBackGround.png"); //rather than adding component in the mainScreen //add components in this verticalManager and then // add this manager to mainScreen contentManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) { protected void paintBackground(Graphics g) { g.drawBitmap(0,0,img_Background.getWidth(),img_Background.getHeight(),img_Background,0,0); //Background img } protected void sublayout( int maxWidth, int maxHeight ) { int width = Display.getWidth(); int height = Display.getHeight() - headerManager.getHeight(); super.sublayout( width, height); setExtent( width, height); } }; // create a couple of buttons for testing only contentManager.add(new ButtonField("Button1")); contentManager.add(new ButtonField("Button2")); contentManager.add(new ButtonField("Button3")); contentManager.add(new ButtonField("Button4")); contentManager.add(new ButtonField("Button5")); contentManager.add(new ButtonField("Button6")); contentManager.add(new ButtonField("Button7"));        contentManager.add(new ButtonField("Button8"));
        contentManager.add(new ButtonField("Button9"));
        contentManager.add(new ButtonField("Button10"));       
        contentManager.add(new ButtonField("Button11"));
        contentManager.add(new ButtonField("Button12"));
        contentManager.add(new ButtonField("Button13"));
        contentManager.add(new ButtonField("Button14"));
        contentManager.add(new ButtonField("Button15"));
        contentManager.add(new ButtonField("Button16"));
        contentManager.add(new ButtonField("Button17"));  
        contentManager.add(new ButtonField("Button18"));
        contentManager.add(new ButtonField("Button19"));
        contentManager.add(new ButtonField("Button20"));
        contentManager.add(new ButtonField("Button21"));
        contentManager.add(new ButtonField("Button22"));
        contentManager.add(new ButtonField("Button23"));
        contentManager.add(new ButtonField("Button24"));
        contentManager.add(new ButtonField("Button25"));
        contentManager.add(new ButtonField("Button26"));
        contentManager.add(new ButtonField("Button27"));
        contentManager.add(new ButtonField("Button28"));
        contentManager.add(new ButtonField("Button29")); this.add(contentManager); } protected void sublayout( int width, int height ) { setExtent(width,height ); setPosition( 0,0 ); layoutDelegate(width,height ); } }

 

 

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Rather than adding the background image in the contentManager add it directly to the screen.

 

So comment out the paintBackground() method inside the contentManager.

And override paint() method in the screen (add at the end of your class). 

 

 

public void paint(Graphics graphics) { graphics.clear(); graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),

img_Background, 0, 0); super.paint(graphics); }

 

Regards

Bikas

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Bikas i tried doing what you said i.e i commented the paintBackground() inside the content Manager and override the paint() method and sublayout()...its working perfectly......Thank u........But i have one more problem i.e it is possible to paint the HeaderManager i.e the heading with the same image that we use in the content Manager...i.e instad og using the setBackgroundColor() method and painting a different color  to the header is it possible to place a image in the header manager.....so that both HeaderManager and ContentManager look alike  and along with that have the property of scrolling only the contentmanager and Header manager leave it constant........Kindly Help...........

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Hi Rab............Actually as Bikas said i comented the paint() methos which is present inside the ContentManager and i have override paint() method in the screen (add at the end of the class) , along with even defined a subLayout method.....Now its working good ....But lastly one more problem i.e .... is it possible to paint the HeaderManager i.e the heading with the same image that we use in the content Manager...i.e instead of using the setBackgroundColor() method and painting a different color  to the header is it possible to place a image in the header manager.....so that both HeaderManager and ContentManager look alike...........  and along with that have the property of scrolling only the contentmanager and Header manager to be constant........Kindly Help...........And Thanks for ur code..........
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Try with drawing a transparent image as your headerManager's background.

 

Try with replacing your headerManager with this:

 

final int imageWidth = demoText.getPreferredWidth(); final int imageHeight = demoText.getPreferredHeight(); int dataTransparent[] = new int[imageWidth * imageHeight]; final Bitmap transparentImage = new Bitmap(imageWidth, imageHeight); transparentImage.setARGB(dataTransparent, 0, imageWidth, 0, 0, imageWidth, imageHeight); headerManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.drawBitmap(0,0,imageWidth, imageHeight, transparentImage,0,0); } };

 

Regards

Bikas

 

 

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Hi Bikas its working its great, can u pls explain me what does the following instructionis mean in ur code actually couldnt understand technically

 

int dataTransparent[] = new int[imageWidth * imageHeight];

 

transparentImage.setARGB(dataTransparent, 0, imageWidth,0, 0, imageWidth, imageHeight);

 

 

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

You can create an image from a data array which contains the ARGB values of the image size.

Array of ARGB data that will be used as the new bitmap data. Each pixel is stored in 0xAARRGGBB format.

Here dataTransparent array contains transparent data by default.

 

And setARGB() method is used to set data into the transparentImage.

See javadoc of the setARGB() method in the Bitmap Class.


Regards

Bikas

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

Ok, Thank u Bikas for the solution u have a helped me a ot regarding this query, I would also like to Thank Rab for this precious guidence too.......... 
New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: how to Scroll only a part of screen......

  Bikas  can i have 2 or 3 screens in which i need to implement the scroll content logic with keeping the header constant........i need to implement in 3 screens........... So it would be best if i keep this Header code in sepearate a seperate customised class and i call this class when requried.....i tried coding a customed class with the code which u sent which i have mentioned below....

 

       

final int imageWidth = demoText.getPreferredWidth(); final int imageHeight = demoText.getPreferredHeight(); int dataTransparent[] = new int[imageWidth * imageHeight]; final Bitmap transparentImage = new Bitmap(imageWidth, imageHeight); transparentImage.setARGB(dataTransparent, 0, imageWidth, 0, 0, imageWidth, imageHeight); headerManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.drawBitmap(0,0,imageWidth, imageHeight, transparentImage,0,0); } };

              can u pls help me to keep this entire code in sepearate class calling it a customised HorizontalFieldmanager and when i required i call his class with this code and use the methods......can this be possible kindly help me i this regard.........