Specificare la larghezza e l'altezza per Editfield fa una difficoltà a vedere il testo in BlackBerry

StackOverflow https://stackoverflow.com/questions/9529131

  •  16-11-2019
  •  | 
  •  

Domanda

Ho usato EditField con una larghezza e un'altezza specificati che funziona bene ma, quando sto entrando nel testo in EditField, non riesco a vedere il testo e alcune volte in cui sto facendo clic su che sto ottenendo NullPointerException.Non sono in grado di capire se il testo è inserito o meno.Inoltre, non riesco a vedere il cursore nel mio campo.Se ci sono errori, per favore dammi suggerimenti.

Il mio codice è:

       private EditField edto;
       private int tosetWidth =400 ,tosetHeight = 50;
       public WelcomeScreen()
       {
           /* Border For EditFields */
           Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);

           edto = new EditField(){

           protected void layout(int width, int height)
           {        
               setExtent(tosetWidth, tosetHeight);

           }

       };

       edto.setBorder(bdr);
.

È stato utile?

Soluzione

Text not showing because of this

protected void layout(int width, int height)
        {        
            setExtent(tosetWidth, tosetHeight);

        }

just remove and try your code is working

if you want to edit field with vertical scrolling and fixed size try following

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("My Edit box Example");

        VerticalFieldManager vr=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR)
        {
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(200,100);
                setExtent(200, 100);
            }
        };

        Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
        EditField edto = new EditField(){
            public void paint(Graphics g) 
            {
                getManager().invalidate();
                super.paint(g);
            }
     };

     vr.setBorder(bdr);
     vr.add(edto);
     add(vr);
     }
}

you can get output as following

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top