2011-06-10 104 views
2

我在我的設計中使用了較小的按鈕,我想要一個帶有較小按鈕的 ChoiceField。按鈕技術不像我期望的ChoiceField那樣工作。我能夠改變大小,但按鈕呈現不合格。如何更改ChoiceField中按鈕的大小?BlackBerry ChoiceField按鈕尺寸

ChoiceField choiceMode = 
    new ChoiceField(
     searchModel.getPickerLabel(SearchOptions.PICKER_MODE),modes.length,0) { 
      public Object getChoice(int index) throws IllegalArgumentException { 
       return modes[index]; 
      } 

      public int getPreferredHeight() { 
       return 40; 
      } 

      protected void layout(int width, int height) { 
       super.layout(width, 40); 
       setExtent(width, 40); 
      } 
     }; 

回答

0

我使用這個類::

public class JOChoiceField extends ObjectChoiceField { 
     int setWidth; 
     int setHeight; 

     public JOChoiceField (String text, Object[] choices, long setStyle, int initIndex, int pSetWidth, int pSetHeight) { 
      super(text, choices, initIndex, setStyle); 
      setWidth = pSetWidth; 
      setHeight = pSetHeight; 
     }   
     public int getPreferredWidth() { 
      return setWidth; 
     } 
     public int getPreferredHeight() { 
      return setHeight; 
     }   
     public void getFocusRect(XYRect rect) {   
      rect.set(getFont().getAdvance(getLabel()), 0, setWidth, setHeight);  
     }  
     protected void layout(int width, int height) { 
      int useWidth; 
      int useHeight; 

      useWidth = getPreferredWidth(); 
      useHeight = getPreferredHeight(); 

      setExtent(setWidth, setHeight); 
      super.layout(useWidth, useHeight);   
     }     
}; 

- -

MyCustomChoiceField= new JOCChoiceField("",MyArrayofItems,ObjectChoiceField.FIELD_LEFT|ObjectChoiceField.FOCUSABLE,0,100,50);   
MyCustomChoiceField.setChangeListener(this);     
MyCustomChoiceField.setFont(Font.getDefault().derive(Font.BOLD,6,2));  
add(MyCustomChoiceField);