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
Dan277
Posts: 21
Registered: ‎04-10-2013
My Device: All
Accepted Solution

Help needed with custom dialog

[ Edited ]

I have created a custom help dialog box. The problem is the 5 buttons don't fit correctly in my horizontal field manager on some blackberry devices. How can I make them fit? I have tried to use my own custom buttons that allow me to specify their width and height, but I am unable to get the width of the dialog so I cannot determine what width the buttons should be.

 

import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class HelpDialog extends Dialog
{
	static int ButtonPressed;
    HorizontalFieldManager hfmChoices = new HorizontalFieldManager();
    ButtonField cmdFirst = new ButtonField("|<")
    {
    	protected boolean navigationClick(int status, int time)
    	{
    		ButtonPressed = 0;
    		close();
    		return true;
		}
    };
    ButtonField cmdPrev = new ButtonField("<")
    {
    	protected boolean navigationClick(int status, int time)
    	{
    		ButtonPressed = 1;
    		close();
    		return true;
		}
    };
    ButtonField cmdNext = new ButtonField(">")
    {
    	protected boolean navigationClick(int status, int time)
    	{
    		ButtonPressed = 2;
    		close();
    		return true;
		}
    };
    ButtonField cmdLast = new ButtonField(">|")
    {
    	protected boolean navigationClick(int status, int time)
    	{
    		ButtonPressed = 3;
    		close();
    		return true;
		}
    };
    ButtonField cmdClose = new ButtonField("Close")
    {
    	protected boolean navigationClick(int status, int time)
    	{
    		close();
    		return true;
		}
    };

    public HelpDialog(String message, int page, int maxPages)
    {
        super("Help (Page: " + page + " of " + maxPages + ")\n\n" + message + "\n", null, null, -1, null, 0);
        ButtonPressed = -1;
        if (page <= 1)
        {
        	cmdFirst.setEnabled(false);
        	cmdPrev.setEnabled(false);
        }
        if (page >= maxPages)
        {
        	cmdNext.setEnabled(false);
        	cmdLast.setEnabled(false);
        }
        hfmChoices.add(cmdFirst);
        hfmChoices.add(cmdPrev);
        hfmChoices.add(cmdNext);
        hfmChoices.add(cmdLast);
        hfmChoices.add(cmdClose);
        add(hfmChoices);
    }
}

 Thank you

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help needed with custom dialog

If you really must have them appearing horizontally, then you are gong to have to create your own layout Manager to use in place of the HorizontalFieldManager.  HFM will not force contained Fields into a particular size, instead it gives the Fields a maximum width and asks them to tell it how much they actually want.  This process of layout appears quite complicated, and it can be, but once you understand it it makes semse.  Here are some KB articles to help you make sense of it:

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

 

In this case, you can probably make use of a Manager that already does for you.  You can probably use the

EvenlySpacedHorizontalFieldManager

which you will find as part of this toolkit:

http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...

 

I think you will be able to just download the source, add this Manager to your project and use it instead of the HFM. 

 

You might find that the Buttons don't work so well - then perhaps the toolkit buttons will work better constrained in this way. 

Please use plain text.
Contributor
Dan277
Posts: 21
Registered: ‎04-10-2013
My Device: All

Re: Help needed with custom dialog

I've tried with HorizontalButtonFieldSet and that just messed everything up. Then I tried with EvenlySpacedHorizontalFieldManager, but that would not work either. The last button still would not fit correctly. I've decided I'm just going to release my program as it is. It's only the close button for the help window that won't display text on some devices. Hopefully, that won't annoy my customers too much. I think the only correct way to use managers other that the AbsoluteFieldManager, is to not use them at all. The problem is that relies on me being able to get the dimensions of the screen in order to size and position objects correctly.

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help needed with custom dialog

Most people don't need a close button, they expect ESC key to do that for them.

 

That said, I disagree with this statement:

"I think the only correct way to use managers other that the AbsoluteFieldManager, is to not use them at all."

 

Designing a User Experience that works well on multiple devices is difficult, and I don't think a one size fits all approach works.  In addition, I don't have the time to design specific screen formats for each device type, and though this is not going to happen now, I did not want to rework screen designs whenever a new device came out.  I think it is possible to create a shared UI experience taking into consideration the size of the screen, and whether it is touch or not.  If you want to read my thoughts on this, have a look at the UI tutorial you will find here:

 

http://supportforums.blackberry.com/t5/Java-Development/Tutorials-for-new-developers-Part-1/m-p/1621...

Please use plain text.