0

I want to add editfield and labelfield on same line . first editfield and then buttonfield . I have tried many times but it didn't work for me .I have added horizontal field manager and also used tables but none of it can help . The issue is it is not showing the buttonfield,i can see only editfield. enter code here

 public class MyScreen extends MainScreen {
  /**
    * Creates a new MyScreen object
   */
 public MyScreen()
 {        
     // Set the displayed title of the screen       
     setTitle("MyTitle");



     HorizontalFieldManager m= new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);

     final GridFieldManager   grid  = new GridFieldManager(4,4,0); 

     grid.setColumnPadding(5);
     grid.setRowPadding(5);

     EditField c= new EditField("","",5,EditField.EDITABLE);
  //   m.add(c);
   Border border=BorderFactory.createRoundedBorder(new XYEdges(10,10,10,10),Border.STYLE_SOLID); 




     grid.setBorder(border);
     ButtonField b= new  ButtonField("Select ",ButtonField.CONSUME_CLICK);
     //m.add(b);
     grid.insert(b,1);
     grid.insert(c,0); 
     //add(m);
     add(grid);                          
    } 
 }
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Shaikh Azhar Alam
  • 173
  • 1
  • 3
  • 16

2 Answers2

1

Override getPreferredWidth() of both EditField and ButtonField like this:

public int getPreferredWidth() {
    return Display.getWidth()/2;
}
Ahmet Gulden
  • 2,063
  • 2
  • 15
  • 23
0

Override sublayout() and layout() method of your EditField & ButtonField than set its width Ex: 100 .. now add both this field in your m.add(); .. its works ..

Hitarth
  • 1,950
  • 3
  • 27
  • 52