1. computerwolf's Avatar
    I have the following code which is a custom RichTextField. Many of these are placed in a VerticalFieldManager and scrolled through. In OS 4.3 and 4.5 when one of the fields gets focus and is highlighted, the entire field is moved onto the screen. However in 4.6.0, only 2 lines of the field are brought onto the screen and the rest is hidden until the next field is moved up. I am confused because the focusRect.height variable is the correct height of the field. Is this a bug or something I am missing in my code?
    Code:
    class TextRichTextField extends RichTextField {
    			
    			public TextRichTextField(String text){
    				super(text);
    			}
    			
    			public TextRichTextField(String text, long style){
    				super(text, style);
    			}
    			
    			XYRect focusRect;
                protected void onFocus(int direction) {
                    if ( focusRect == null ) {
                        focusRect = this.getExtent();
                    }
                    super.onFocus(direction);
                    invalidate();
                }
                
                protected void unFocus() {
                    super.onUnfocus();
                    invalidate();
                }
                
                public boolean isSelectable() {
                    return false;
                }
                
                public boolean isFocusable() {
                    return true;
                }
                
                protected void drawFocus(Graphics g, boolean on) {
                    if ( focusRect != null ) {
                    	super.drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS | Field.HIGHLIGHT_SELECT, on, 0, 0, focusRect.width, focusRect.height);
                    	this.invalidate();
                    	super.drawFocus(g, on);
                    }
                    else {
                        super.drawFocus(g, on);                    
                    }
                }
                public void getFocusRect(XYRect rect) {
                    if ( focusRect == null ) {
                        super.getFocusRect(rect);
                    }
                    else {
                        rect.x = 0;
                        rect.y = 0;
                        rect.width = focusRect.width;
                        rect.height = focusRect.height;
                    }                 
                }            
                public int moveFocus(int amount, int status, int time) {
                	return amount;
                }
                
                public void paint(Graphics graphics) {
               	    graphics.setColor(Color.WHITE);
               	    super.paint(graphics);
               	  }
    		}
    Last edited by ComputerWolf; 07-22-09 at 12:41 PM.
    07-22-09 03:10 AM
  2. computerwolf's Avatar
    Turns out the change is happening in 4.6 and above. 4.3 and 4.5 both focus the field to be fully on the screen. It may just be something in the code that I am missing and is causing it to act differently on the newer OS's.
    07-22-09 12:43 PM
  3. computerwolf's Avatar
    Problem solved! If I extend LabelField as opposed to RichTextField all works as it should. Not that I understand why there's a difference, but it works.
    07-23-09 10:45 PM
LINK TO POST COPIED TO CLIPBOARD