Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 31
Registered: ‎08-26-2011
My Device: Torch 9810
My Carrier: AT&T
Accepted Solution

ButtonField label displays ".." rather than label text

I have a button field that created with the label "OK", however, when it displays it shows "..".   My code is below:

 

  _btnOK = new ButtonField("OK",  ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY );
         _btnOK.setChangeListener(new FieldChangeListener() {
        	public void fieldChanged(Field field, int context)
        	{
        		if (!_txtfilename.getText().equals("")) {
        			buildPath();
        			int lastSlash = _currentPath.lastIndexOf('/');
        			if (lastSlash == -1)
        			{
        				_currentPath += _txtfilename.toString();
        			}
        			else
        			{
        				_currentPath = _currentPath.substring(0, lastSlash + 1);
        				_currentPath += _txtfilename.toString();
        			}
        			createresultfile(_currentPath);
         		}
        		else {
        			_currentPath = null;
        		}
        		close_dialog();
        	}
        });
               
         HorizontalFieldManager hfm = new HorizontalFieldManager()
         {
        	 
        	 public void sublayout(int width, int height) {
        		 int xpos = 0;
        		 int ypos = 0;
        		 int widfield1 = (int) (width * .8);
        		 int widfield2 = (int) (width * .2);
        		 int hieghthfm = 40;
        		 Field field = getField(0);
            
        		 setPositionChild(field, xpos, ypos+5);
        		 layoutChild(field, widfield1, (int) (hieghthfm * .80));
            
        		 Field field1 = getField(1);
            
        		 setPositionChild(field1, xpos+widfield1, ypos);
        		 layoutChild(field1, widfield2, widfield2);  
        		 setPosition(width, hieghthfm);
        		 setExtent(width, widfield2); 
      	 } 
        };
         hfm.add(_txtfilename);
    	 hfm.add(_btnOK);
    	 dfm.addCustomField(hfm);
    	              
        _olf = new ObjectListField();
        dfm.addCustomField(_olf);
        updateList(path);
        _txtfilename.setFocus();

Any help would be appreciated. 

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: ButtonField label displays ".." rather than label text

One thing I would immediately change in your code, regardless of anything else - make hfm a Manager: you fully override sublayout, so you don't need to extend HFM. Implement your own getPreferredWidth and getPreferredHeight to be on the safe side and you've got yourself a fine custom layout Manager.

You have a typo in your setExtent - it should probably be setExtent(width, hieghthfm). Your setPosition also doesn't make much sense - decide what you actually want to have there. It sets the X, Y of the upper left corner of your Manager. I'm not sure you need it at all - your DialogFieldManager should take care of that.

 

Finally - check how much width you pass into your layoutChild(field1, ...) - your widfield2 might be too small for it to display anything meaningful. Don't forget - ButtonField has its own, relatively complicated, layout, including some padding around the text.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 102
Registered: ‎07-26-2011
My Device: Not a blackberry user
My Carrier: None

Re: ButtonField label displays ".." rather than label text

Greetings.

This as easy as you guess.

The size that the manager is setting to the button is not large enough to show the whole text. That's why the button switches its text to an ellipsis (which is actually showing incomplete as you can notice).

Change the sublayout method to something more dynamic by using the needed size for the button as the given size.

Let me know if this was helpful or if you have a solution.

Johan Guzmán - In case my answer pleased you, give a press to the LIKE button, please!! Mark this post as solution if it solved your problem.