2014-03-29 4 views
4

레이블 필드에서 가로로 스크롤하고 싶습니다.Blackberry의 labelField에서 가로로 스크롤하는 방법

In Below image, Long Text which is E-mail ID is not scrolled.

나는 정의 GridField 관리자에서이 레이블 필드를 추가하고있다. 다음은 Custom GridField Manager의 코드입니다.

public class CustomGridFieldManager extends Manager { 
private int[] columnWidths; 
private int columns; 
private int allRowHeight = -1; 


public CustomGridFieldManager(int columns, long style) { 
    super(style); 
    this.columns = columns; 
} 


public CustomGridFieldManager(int[] columnWidths, long style) { 
    super(style); 
    this.columnWidths = columnWidths; 
    this.columns = columnWidths.length; 

} 

public CustomGridFieldManager(int[] columnWidths, int rowHeight, long style) { 
    this(columnWidths, style); 
    this.allRowHeight = rowHeight; 
} 

protected boolean navigationMovement(int dx, int dy, int status, int time) { 

    int focusIndex = getFieldWithFocusIndex(); 
    while(dy > 0) { 
     focusIndex += columns; 
     if (focusIndex >= getFieldCount()) { 
      return false; // Focus moves out of this manager 
     } 
     else { 
      Field f = getField(focusIndex); 
      if (f.isFocusable()) { // Only move the focus onto focusable fields 
       f.setFocus(); 
       dy--; 
      } 
     } 
    } 
    while(dy < 0) { 
     focusIndex -= columns; 
     if (focusIndex < 0) { 
      return false; 
     } 
     else { 
      Field f = getField(focusIndex); 
      if (f.isFocusable()) { 
       f.setFocus(); 
       dy++; 
      } 
     } 
    } 

    while(dx > 0) { 
     focusIndex ++; 
     if (focusIndex >= getFieldCount()) { 
      return false; 
     } 
     else { 
      Field f = getField(focusIndex); 
      if (f.isFocusable()) { 
       f.setFocus(); 
       dx--; 
      } 
     } 
    } 
    while(dx < 0) { 
     focusIndex --; 
     if (focusIndex < 0) { 
      return false; 
     } 
     else { 
      Field f = getField(focusIndex); 
      if (f.isFocusable()) { 
       f.setFocus(); 
       dx++; 
      } 
     } 
    } 
    return true; 
} 

protected void sublayout(int width, int height) { 
    int y = 0; 
    if (columnWidths == null) { 
     columnWidths = new int[columns]; 
     for(int i = 0; i < columns; i++) { 
      columnWidths[i] = width/columns; 
     } 
    } 
    Field[] fields = new Field[columnWidths.length]; 
    int currentColumn = 0; 
    int rowHeight = 0; 
    for(int i = 0; i < getFieldCount(); i++) { 
     fields[currentColumn] = getField(i); 
     layoutChild(fields[currentColumn], columnWidths[currentColumn], height-y); 
     if (fields[currentColumn].getHeight() > rowHeight) { 
      rowHeight = fields[currentColumn].getHeight(); 
     } 
     currentColumn++; 
     if (currentColumn == columnWidths.length || i == getFieldCount()-1) { 
      int x = 0; 
      if (this.allRowHeight >= 0) { 
       rowHeight = this.allRowHeight; 
      } 
      for(int c = 0; c < currentColumn; c++) { 
       long fieldStyle = fields[c].getStyle(); 
       int fieldXOffset = 0; 
       long fieldHalign = fieldStyle & Field.FIELD_HALIGN_MASK; 
       if (fieldHalign == Field.FIELD_RIGHT) { 
        fieldXOffset = columnWidths[c] - fields[c].getWidth(); 
       } 
       else if (fieldHalign == Field.FIELD_HCENTER) { 
        fieldXOffset = (columnWidths[c]-fields[c].getWidth())/2; 
       } 

       int fieldYOffset = 0; 
       long fieldValign = fieldStyle & Field.FIELD_VALIGN_MASK; 
       if (fieldValign == Field.FIELD_BOTTOM) { 
        fieldYOffset = rowHeight - fields[c].getHeight(); 
       } 
       else if (fieldValign == Field.FIELD_VCENTER) { 
        fieldYOffset = (rowHeight-fields[c].getHeight())/2; 
       } 

       setPositionChild(fields[c], x+fieldXOffset, y + fieldYOffset); 
       x += columnWidths[c]; 
      } 
      currentColumn = 0; 
      y += rowHeight; 
     } 
     if (y >= height) { 
      break; 
     } 
    } 
    int totalWidth = 0; 
    for(int i = 0; i < columnWidths.length; i++) { 
     totalWidth += columnWidths[i]; 
    } 
    setExtent(totalWidth, Math.min(y, height)); 
} 

} 다른 클래스에서

, 나는이 사용자 정의 GridField 관리자 클래스를 사용합니다.

int[] width = { (int) (Display.getWidth()/2.9), 
       (int) (Display.getWidth()/1.1) }; 

     final CustomGridFieldManager gfm_transactioninfo = new CustomGridFieldManager(
       width, 35, Manager.VERTICAL_SCROLL | Manager.FIELD_HCENTER 
         | FOCUSABLE) { 
      protected void paint(Graphics graphics) { 
       // TODO Auto-generated method stub 
       graphics.setColor(AppData.color_black); 
       super.paint(graphics); 
      } 

     }; 
     gfm_transactioninfo.setMargin(10, 0, 0, 10);// set top and left margin 

이 같은 Labelfiled를 추가

,

lbl_CustEmail = new LabelField("Customer Email", LabelField.FOCUSABLE); 
     lbl_CustEmail.setFont(label_font); 

     value_CustEmail = new LabelField(": " +trandtail[0].getFromEmail()); 
     value_CustEmail.setFont(label_font); 

    gfm_transactioninfo.add(lbl_CustEmail); 
    gfm_transactioninfo.add(value_CustEmail); 

중 하나가 다음 수평으로 스크롤 좀 도와주세요하는 방법에 대해 어떤 생각을 가지고 있다면. 미리 감사드립니다.

+0

시도하십시오. http://stackoverflow.com/questions/2613062/how-can-i-display-scroll-text-like-marque-in-blackberry-using-j2me – Signare

+0

트랙 패드 사용자가 어떻게 할 것으로 기대합니까? 스크롤하면 navigationMovement를 재정의 할 수 있습니까? –

+0

FieldManager에서 레이블을 가로로 스크롤 할 수 있도록 설정할 수없는 특별한 이유가 있습니까? – Kevin

답변

1

그리드보기를 사용자 정의하여 레이블 필드 앞뒤에 하나의 FocusableNullField를 추가 할 수 있습니다. 이렇게하면 첫 번째 null 필드에 포커스가있는 경우 다음 focusablenullfield로 가로로 스크롤하고 명시 적으로 labelfield를 스크롤 가능하게 만들 수 있습니다.

+1

이것이 효과가 있다고 생각하지 마라. NullFields를 추가하는 것만으로 시작과 끝에 집중할 수 있고 스크롤 할 수는 없다는 것을 의미한다. LabelField를 포커스 가능하게 만들면 처음부터 NullField와 유사한 효과를 얻을 수 있으며 LabelField를 '캐럿'을 유지하는 RichTextField로 대체 할 수 있으므로 스크롤 할 수 있습니다. 비슷한 옵션이 많이 있지만 나에게있어 문제는 제공되는 navigationMeovement 오버라이드가있는 트랙 패드 장치에서 작동하지 않는다는 것입니다. 그러므로 OP가 대답하지 않은 나의 질문. –