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
Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

How to create a notepad kind of multiline editor

Hi

I want to create a Multi line Editor with Border and defined height.

I tried by creating AutoTextEditField with a border, but it is still showing as single line.

when we entered more than 1 line, then the editor is expanding to those many lines.

It is keep on expanding more lines when we enter more line.

 

Where as I need to an editor with minimum 4 lines and need to have a scroll bar if we entered four lines.

 

Also I want to have the border more fanciful (not like defined Border.STYLE_*). I have the pictures, but I am not able to attach the same in this Link

 

Can any one help.

 

Thanks

Siva

Thanks
Siva
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: How to create a notepad kind of multiline editor

One of the developer posts or docs has a custom manager class that displays a fixed size field that scrolls instead of expanding.  Using it should prevent your editor field from expanding.

 

You can google it or try using the following code...I modified the code from the docs to fit in with a program I was writing.

 

 

public class postManager extends VerticalFieldManager
{
   //Define some variables to be used
    //in the class
    private int managerWidth;
    private int managerHeight;

    //Pass in the fixed height and width for our object
    public postManager(EditField f, int width, int height)
    {
        //This call to super will help keep the object in place
        super(Manager.NO_VERTICAL_SCROLL);
        managerWidth = width;
        managerHeight = height;
        //vfm will allow scrolling within the object
        VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
        vfm.add(f);
        add(vfm);
    }

    //If this call to sublayout was made by the system then
    //both parameters would be passed with a value of 0.
    //This check and adjustment keeps the fixed properties
    //maintained.
    public void sublayout(int width, int height)
    {

        if (managerWidth == 0) {
            managerWidth = width;
        }
        if (managerHeight == 0) {
            managerHeight = height;
        }
        super.sublayout(managerWidth, managerHeight);
        //Force the extent of our manager.
        //This will force the height of the object
        //where the above super.sublayout() call will
        //set the width.
        setExtent(managerWidth,managerHeight);
    }

 

 

Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

Re: How to create a notepad kind of multiline editor

Thanks for  your reply

 

I think your code will make sure to have fixed space of Veritical Field Manager from Main Screen.

Infact your code will help for another solution I am looking for.

 

I am asking for a Text Editor with fixed Height and is capable of entering multi line with scroll bar.

 

Here is what I am doing

 

// Created a Vertical Field Manager (ofcourse I did not fix the Height of Vertical Field Manager) and added to a Screen.

 

_fieldManagerMessage = new VerticalFieldManager();

add(_fieldManagerMessage);

 

// Creating Border types

XYEdges thickPadding = new XYEdges(10,10,10,10);
Border roundedBorder = BorderFactory.createRoundedBorder(thickPadding, Border.STYLE_SOLID);
Background solidBackground = BackgroundFactory.createSolidBackground(Color.WHITE);

 

// Creating Auto Text Edit Field
_MessageEditField = new AutoTextEditField("Message: ", "", 255, BasicEditField.SPELLCHECKABLE);

 

// Adding Borders

_MessageEditField.setBorder(roundedBorder);
_MessageEditField.setBackground(solidBackground);

 

// Adding Auto Text Edit Field to Vertifcal Field Manager

_fieldManagerMessage.add(_MessageEditField);

 

 

Now, in this case, when I am editing the Editor, it is first showing one line and when I am entering multiline, it is expanding the Vertical field Manager space in Main Screen and also Editor Space.

 

What I want to have is fixed height of AutoTextEditField and is scrollable for Multiline with visible Scroll Bar.

 

 

Thanks

Siva

Thanks
Siva
Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

Re: How to create a notepad kind of multiline editor

Please help me in this context.

 

Thanks

Siva

Thanks
Siva
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: How to create a notepad kind of multiline editor

I'm a litle confused.  When you say "multiline" do you mean that you want to be able to enter multiple lines of text in the same field, or that you want actual lines in the AutoEditTextField?

 

If it's the first, then the code I posted should do just that with some modification to fix the height of the passed in field...

Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

Re: How to create a notepad kind of multiline editor

I am looking for second part of your statement i.e. "that you want actual lines in the AutoEditTextField?"

 

Thanks

Siva

 

Thanks
Siva
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: How to create a notepad kind of multiline editor

I think it's because you're using one AutoEditTextField and painting a border around it.  The AutoEditTextField will expand to hold the text...which means the border will expand with the field.

 

You may want to try using a SeparatorField instead of using borders for the lines in your field.

Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

Re: How to create a notepad kind of multiline editor

Yes, AutoEditTextField is expanding to hold the text.

 

I want to have have an editor just like our notepad application on Windows which has Vertical Scroll bar (No Horizontal Bar on wrappable Setting).

 

Infact, similar window will be seen while replying to this post.

 

Here is the snap shot in text format of Multi line editor (as I cannot post the Image)

 

 --------------------------------
|  --------------------------  ^ |
| | This is a multi line     | | |
| | editor which will scroll | | |
| | with this block of editor| | |
| | so please indicate me the| | |
| | Blackberry API for same. | | |
| | Scroll below for more... | | |
|  --------------------------  v |
 --------------------------------

Please help in this regard

Thanks Siva

 

Thanks
Siva
Developer
Posts: 75
Registered: ‎02-08-2010
My Device: 9000
My Carrier: Airtel

Re: How to create a notepad kind of multiline editor

[ Edited ]

Finally I got to some extent of what I want. It has one Rect and is fixed width and height with scrollable text inside

Infact it is close to your code and found in Knowledge Base at followings Links

 

http://na.blackberry.com/eng/devjournals/resources/journals/jul_2005/creating_textbox_field.jsp

http://supportforums.blackberry.com/t5/Java-Development/Multiline-LabelField/m-p/210226

 

etc.

 

In addition to the code found in the above links, I have added one more feature,

i.e. instead of drawing an Rectangle around the border, I have put a bitmap (which has nice rounded edges) and placed it behind. It's working for me.

 

There is one last requirement that needs your support, i.e. implementing Vertical Scroll Bar on right side of Text Field.

Please help in this regard

 

Pasting the code for reference

 

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.AutoTextEditField;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

public class myTextBoxField extends VerticalFieldManager {

private int managerWidth;
private int managerHeight;
private Bitmap BackGroundBitmap;
private EditField editField;

public myTextBoxField(int width, int height) {

super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;

Bitmap resizeBitmap = Bitmap.getBitmapResource("SingleBar.PNG");
BackGroundBitmap = new Bitmap(width, height);
resizeBitmap.scaleInto(BackGroundBitmap, Bitmap.FILTER_BILINEAR);

VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);

editField = new EditField() {
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}
};

XYEdges thickPadding = new XYEdges(10,10,10,10);
Border TransparentBorder = BorderFactory.createSimpleBorder(thickPadding,Border.STYLE_TRANSPARENT);
vfm.setBorder(TransparentBorder);

vfm.add(editField);
add(vfm);
}

public void paint(Graphics g) {
//g.drawRect(0, 0, getWidth(), getHeight());
g.drawBitmap(0, 0, managerWidth, managerHeight, BackGroundBitmap, 0, 0);
super.paint(g);
}

public void sublayout(int width, int height) {
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth,managerHeight);
}

public String getText() {
return editField.getText();
}
public void setText(String text) {
editField.setText(text);
}
}

 

 

Thanks
Siva
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: How to create a notepad kind of multiline editor

 


 

Finally I got to some extent of what I want. It has one Rect and is fixed width and height with scrollable text inside

Infact it is close to your code and found in Knowledge Base at followings Links

 

http://na.blackberry.com/eng/devjournals/resources/journals/jul_2005/creating_textbox_field.jsp

http://supportforums.blackberry.com/t5/Java-Development/Multiline-LabelField/m-p/210226

 


 

That's the same link I mentioned in the original post...in fact I mentioned it when i posted the code...remember I said I'd modified the code and you could try it but the original link was out in the docs somewhere?

 

 

 


 

 

There is one last requirement that needs your support, i.e. implementing Vertical Scroll Bar on right side of Text Field.

Please help in this regard

 

Pasting the code for reference

 


 

You need to add the VERTICAL_SCROLLBAR style to either your Manager implementation or the VerticalFieldManager passed to the Manager...I forget which one.