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
AntonioJSG
Posts: 35
Registered: ‎10-11-2008
My Device: Not Specified

two fields on same line within screen with vertical manager

Hi, I need to add several lines within a screen with vertical manager.

Each of the lines must have one label field, and BasicEditField horizontally.  The fields must be aligned.

Example:

 

BasicEditField1      RichTextField1

BasicEditField2      RichTextField2

BasicEditField3      RichTextField3

...

 

I must use JDE 4.5  

 

I have written an extended Field with a Manager inside.

 

The constructor will receive the fields to be painted and the column positions for each field, then it will add the fields to the manager, and paint the manager field using the column positions supplied.

 

When running the program, the fields are painted in the right place, but the EditField works as a label ( no input allowed ) and both the RichTextField and EditField are not updateable.

 

Below is the code for the extended field

 

public class HorizontalFields extends Field {

    Field[] fieldsInLine;
    int[] coords;
    Font _font;
    int altura;
    FieldManager contenido;

    public HorizontalFields(Field[] pFields, int[] pCoords) {
        fieldsInLine = pFields;
        coords = pCoords;
        contenido = new FieldManager(fieldsInLine);
        altura = Math.min(fieldsInLine[0].getPreferredHeight(), fieldsInLine[1].getPreferredHeight());
    }

    protected void layout(int witdh, int heigth) {
        setExtent(240, altura);
    }

    protected void paint(Graphics g) {
        contenido.pintese(g);
    }

    private class FieldManager extends Manager {

        public FieldManager(Field[] contents) {
            super(Manager.EDITABLE | Manager.FOCUSABLE);
            for (int col = 0; col < contents.length; col++) {
                add(contents[col]);
            }
        }

        public void pintese(Graphics g) {
            layout(200, altura);
            subpaint(g);
        }

        protected void sublayout(int arg0, int arg1) {
            int ancho = 240;
            int alto = 0;
            for (int i = 0; i < fieldsInLine.length; i++) {
                layoutChild(fieldsInLine[i], 200, fieldsInLine[i].getPreferredHeight());
                setPositionChild(fieldsInLine[i], coords[i], 0);
            }
            setExtent(ancho, alto);
        }

        public int getPreferredWidth() {
            return 100;
        }

        public int getPreferredHeight() {
            return altura;
        }

        protected int nextFocus(int direction, boolean alt) {
            int index = this.getFieldWithFocusIndex();
            if (index == this.getFieldWithFocusIndex()) {
                return super.nextFocus(direction, alt);
            } else {
                return index;
            }
        }
    }
}

 

 

the following code will  add some fields to the screen if you want to test it.

 

Screen newScreen() {

 

basicf = new BasicEditField("Edit:", "inicial", 10, Field.FIELD_RIGHT); 
campos[0] = basicf;
basicf.setText("pw-"+basicf.getPreferredWidth());
richf = new RichTextFieldColor("1,000.00",Field.NON_FOCUSABLE, PlVentaMovil.colorAzul);
campos[1] = richf;
int[] coordX = new int[2];
coordX[0] = 10;
coordX[1] = 150;
HorizontalFields horiz2 = new HorizontalFields( campos, coordX );
this.add(horiz2);

 

Thank you for the advise.

 

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: two fields on same line within screen with vertical manager

I'm not sure of the problem you are having here.  You can use the EditFied.EDITABLE style to make an EditField editable (allow text entry).  Note that a RichtextField is a read only field and does not accept user input.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker