Great ButtonField with label that surrounds it.

Hello

I want to create a great label ButtonField who must dress to the next line.

(1.) I overrode getPreferredWidth/height to adjust the dimensions of the button.

2.) is it possible to get the text to wrap around to the next line.

Is there another way to model a button with text that surrounds to the next line?

I would really appreciate guidance in this regard.

Thank you

-MO.

Well, I had little time to debug the code.  Here's the working version (I'll even integrate it into our project - after a few changes):

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.component.TextField;

public class MultiLineButtonField extends Manager {
    private final static int MAX_LABEL_PADDING = 8; // pixels
    private final static int MIN_LABEL_PADDING = 2; // pixels again
    private final static int NON_FOCUS_COLOR = Color.DARKBLUE;
    private final static int FOCUS_COLOR = Color.BLUE;
    private final static int DISABLED_COLOR = Color.GRAY;
    private final static int FONT_COLOR = Color.WHITE;
    private TextField _label;
    private NullField _focusAnchor;
    private int _width;
    private int _padding;

    public MultiLineButtonField(String labelText, int width, long style) {
        super(style & (FIELD_HALIGN_MASK | FIELD_VALIGN_MASK | USE_ALL_WIDTH | USE_ALL_HEIGHT));
        _label = new TextField(style & SPELLCHECKABLE_MASK | READONLY | NON_FOCUSABLE);
        _label.setText(labelText);
        add(_label);
        _focusAnchor = new NullField(style & FOCUSABLE_MASK) {
            protected void onFocus(int direction) {
                getManager().invalidate();
                super.onFocus(direction);
            }

            protected void onUnfocus() {
                getManager().invalidate();
                super.onUnfocus();
            }
        };
        add(_focusAnchor);
        _width = width;
        if (_width < 2 * MIN_LABEL_PADDING) {
            throw new IllegalArgumentException("Not enough width to lay out MultiLineButtonField");
        }
    }

    protected int nextFocus(int direction, int axis) {
        invalidate();
        return -1;
    }

    protected void sublayout(int width, int height) {
        XYRect childRect;
        if ((width < 2 * MIN_LABEL_PADDING) || (height < 2 * MIN_LABEL_PADDING)) {
            throw new IllegalArgumentException("Not enough room to lay out MultiLineButtonField");
        }
        layoutChild(_label, Math.min(_width, width) - 2 * MIN_LABEL_PADDING, height - 2 * MIN_LABEL_PADDING);
        childRect = _label.getExtent();
        int myWidth = width;
        int myHeight = height;
        if (!isStyle(USE_ALL_WIDTH)) {
            myWidth = Math.min(width, childRect.width + 2 * MAX_LABEL_PADDING);
        }
        if (!isStyle(USE_ALL_HEIGHT)) {
            myHeight = Math.min(height, childRect.height + 2 * MAX_LABEL_PADDING);
        }
        _padding = Math.min((myWidth - childRect.width), (myHeight - childRect.height)) / 2;
        setPositionChild(_label, _padding, _padding);
        layoutChild(_focusAnchor, 0, 0);
        setPositionChild(_focusAnchor, 0, 0);
        setExtent(myWidth, myHeight);
    }

    protected void paintBackground(Graphics g) {
        int prevColor = g.getColor();
        int bgColor;
        if (_focusAnchor.isFocusable()) {
            if (_focusAnchor.isFocus()) {
                bgColor = FOCUS_COLOR;
            } else {
                bgColor = NON_FOCUS_COLOR;
            }
        } else {
            bgColor = DISABLED_COLOR;
        }
        g.setColor(bgColor);
        g.fillRoundRect(0, 0, getWidth(), getHeight(), _padding, _padding);
        g.setColor(prevColor);
    }

    protected void paint(Graphics g) {
        int prevColor = g.getColor();
        g.setColor(FONT_COLOR);
        super.paint(g);
        g.setColor(prevColor);
    }
}

Tags: BlackBerry Developers

Similar Questions

  • Feed the list component with labels that have only certain values.

    I have to be able to sort out shorter labels in the component 'listHolder.list' by values in 'Fan', 'Herdighet', etc., which will be selected of the other items in the list
    (those who do not need to be fed by XML, but the list items own dataProvider)

    Practical example: displays only the labels in listHolder.list that are connected to the "H1" value in "Herdighet" or "H2" "Herdighet" etc.

    I am fairly new to AS3, so I do not know how to start. I appreciate everything you can give clues.

    Here's the code so far:

    //--------------------------

    var loader: URLLoader = new URLLoader();

    loader.addEventListener (Event.COMPLETE, onLoaded);

    listHolder.list. addEventListener (Event.CHANGE, itemChange);

    function itemChange(e:Event):void {}

    var selectedObj:Object = a [listHolder.listSelectedIndex]

    var xml;

    var a: Array = [];

    function onLoaded(e:Event):void {}

    XML = new XML (e.target.data);

    var it: XMLList = xml. Lauvtre;

    for (var i: uint = 0; i < il.length (); i ++) {}

    listHolder.list.addItem ({.child('Botanisk_navn').toString ()label: it [i]+ "\n"+ "-" + it [i].child('Norsk_navn').toString () "});

    a [i] = {'Fan': it [i].child('Farge').toString (), 'Herdighet': it [i].child('Herdighet').toString (),}

    "Høyde": he [i].child('hoyde').tostring (), "Botanisk_navn": he [i] .one ('Botanisk_n avn') m:System.NET.SocketAddress.ToString (),.

    'Norsk_navn': it [i].child('Norsk_navn').toString (), 'Image': it [i] .child ('image'). toString(),

    {"Blomstring": he [i].child('Blomstring').toString (), "Lysforhold": he [i] .one ('Lily book') m:System.NET.SocketAddress.ToString ()};

    }

    }

    Loader.Load (new URLRequest ("lauvtre.xml"));

    Fusion is a good thing.  The more you have to understand this, easy it all comes together when the lights start to go.

    In regard to the 'a' table... If you look at how values are it is attributed originally, they are attributed to the 'i' value of the index.  So, if the first element that passes the test of H1/H2 is the 10th 'i', it means that 10 of the table value is assigned to the first value you found.  The first 9 values in the table are zero as a result.

    But if you use the method push of the array class.

    a.push ({"Fan": he [i].child('Farge').toString (),... etc...});

    then the item is added to the index of the table rather than the 'i' the next clue.  If a table will have the same number of elements as the list and the list and table will agree in regard to pair them up.

  • Still disappointed with Apple TV Surround Sound!

    Well, after several months of use of the Apple TV4, I must say that I am still very disappointed with the sound surround.

    I have an audio receiver system and decent surround speakers, but since the purchase of the ATV4 the sound is not as good as it used to be, and it is poor compared to the other entries like Sky HD for example. I set him up on a possible adjustment of best Audio 7.1.

    Its mainly the question of when I watch a movie. If listening to music it sounds good, but put a movie and I always have to turn up the volume. For example I was listening music to-30db on the amp but watched The good Dinosaur with my family yesterday and has to turn his up - 15db and before someone mentions - 15 is stronger than-30 on my system with 0db reference sound.

    I don't understand why there is a big difference between music and movies. Netflix even sounds better. Sky HD sounds better. I had enough discussions and reviews on here for sure that I put it in place correctly but still his pants.

    Come on get Apple sort it is so frustrating!

    Hello. The sound on the movies is weak to allow plenty of room for loud sounds. The coding of the sound film was made when the film has been digitized. ATV is just passing the bytes on your amp. Sky is a broadcaster, so they compress the audio, distort in the process. Hard to say what Netflix is up to.

  • What happened to the great selection of gadgets that allows to be available?

    What happened to the great selection of gadgets that allows to be available?

    Hello

    1. what exactly is the problem you are facing with gadgets in Windows 7?

    2. you are not able to use the gadgets?

    If you are referring to the Windows Sidebar in Windows Vista, then it is not included in Windows 7. For more information click on the link below.

    What happened to Windows Sidebar?

    http://Windows.Microsoft.com/en-us/Windows7/what-happened-to-Windows-Sidebar

    You can publish your comments for us on the link below.

    http://mymfe.Microsoft.com/Windows%20%207/feedback.aspx?formid=195

  • Problem with labels (bridge)

    Why I can't label tif files?  I have two images that were originally imported in Lightroom and then edited in Photoshop CC.  When I had finished editing, I clicked 'save', and they were created as .tif files.  They are rather large, 1 GB and 2 GB.  I gave them the labels of 'Blue' and 'green '.  When I now look at in Bridge (6.1.1.10 x 64), they are recognized as having 'blue' and 'green' labels that are not the typical bridge labels.  I'm given the labels of 'review' and 'approved', respectively, but if I use the label of the menu drop-down or CNTL + labels do not change.  I was able, somehow, to create in the folder one. BridgeLabelsAndRatings of the file with the correct values, but they still are not displayed in Bridge as "Review" and "approved."  Is this a problem of bridge?  Moreover, my operating system is Windows 10.

    Please remove the label from the images using the Lightroom and export another copy on the desktop and then try to assign the correct label according to the requirement.

    Kind regards

    ~ Mohit

  • Height of a VBox with label and wrapped text

    Hello

    I have a VBox with label and text wrapped inside. The sentence in the text are from an external location and load in the text. I want to know the height of the VBox after that the text was being wrapped and place inside the VBox.

    I used all the properties for VBox as getHeight(), getPrefHeight(), getMinHeight() and getMaxHeight(), but these properties give me what I want.

    Is there another property I am missing or is a short coming of VBox?

    If this is a shortcoming of VBox, what other solution do I?

    Thank you

    AA

    You can register a listener with heightProperty() of the vbox and get it when it changes.

  • Hi all, I keep is typed in the password at startup box, in bars in safari and firefox coupled with a stuck key noise that stops when you press a key, I scanned with antivirus that seems clear, can anyone help?

    Hi all, I get a storm of +'s typed in the password at startup box upward, in bars in safari and firefox coupled with a stuck key noise that stops when you press a key, I scanned with antivirus that seems clear, can anyone help?

    Clings in the key on the keyboard? Wired or wireless keyboard?

    Try to run this program, copy and paste the result in a response. The program was created by Etresoft, a regular contributor.  Use please copy and paste the screenshots can be difficult to read. On the screen with the Options, please open Options and tick the boxes in the bottom 2 before the race. Click on the button "Report share" in the toolbar, select "Copy to Clipboard" and then paste into a response. This will show what is running on your computer. No personal information is shown.

    Etrecheck - Information System

    Reset an Apple Bluetooth mouse or Trackpad wireless keyboard (pairings and other common troubleshooting problems)

    Restart your computer, hold down the option/alt - P - R keys command before the gray screen appears. Continue until you hear the startup chime for the second time.

    Reset the NVRAM EXTRA memory

  • How to recharge my hard drive with photos that are stored in iCloud.  After installing a new hard drive, there's no pictures found in the Photos, and I get this error "cannot find system Photo library named"Library.photoslibrary Photos".

    How to recharge my hard drive with photos that are stored in iCloud?  After installing a new hard drive, there's no pictures found in the Photos, and I get this error, "could not find the picture of system library named"Library.photoslibrary Photos".

    Soon as your App Photos or iPhoto lost track of your photo library, or there has not been migrated from your old drive. You can create an empty library and probably enable iCloud photo library for photos to upload to the cloud.

    Designate a library in pictures - Apple Support System

  • HP workspace: is it possible to try HP work space with applications that uses my business?

    Hey everybody,

    Is there a way to try HP work space with applications that uses my business?

    Thank you

    Bill

    Yes, buyers of all bundle HP Elite x 3 on or before January 31, 2017 can enjoy a free 60 days HP Workspace Premium service launch promotion offer.5 which is more a $150 value per user! 6. contact your partner HP or HP account representative to activate the free promotional offer for 60 days.

  • My ipad is clogged with apps that I deleted

    My ipad air is clogged with apps that I deleted, factory settings and the creation of new space free icloud account, wud I do the same thing for itunes or can I keep itunes?

    You do not have to create a new Apple ID. Delete your old backups iCloud and iTunes and restore the phone to factory settings.

    iCloud: delete a backup device iOS to iCloud

    Find and manage your backups iTunes - Apple Support

    Use iTunes on your Mac or PC to restore your iPhone, iPad or iPod settings - Apple Support

  • Currently using iMac 2007 Yosemite 10.10.5 with 2 GB 667 mhz ddr 2 with 2.4 ghz core 2 duo with intel that I should upg at El Capitan

    Currently using iMac 2007 Yosemite 10.10.5 with 2 GB 667 mhz ddr 2 with 2.4 ghz core 2 duo with intel that I should upg at El Capitan.  Very slow system.  This improvement will speed up?

    In my opinion, unless you upgrade the RAM 6 GB. You can get a kit of RAM 6 GB OWC (www.macsales.com) or you can get a DIMM 4 GB + 2 GB of Crucial (direct purchase) and update the RAM. Your machine likely a 2x1GB DIMMS installed, however if she doesn't 1x2GB DIMM installed everything you need is a 4 GB DIMMS. Once you upgrade the RAM, then you can upgrade to El Capitan, when you upgrade, I think you'll be an improvement in performance. Although technically El Capitan (and Yosemite) will run on 2 GB, the user experience should be quite poor.

    Good luck.

  • I continue to receive emails with images that do not appear?

    Hello

    I continue to receive emails with images that do not display, simply to show a Red Cross in the top left box from where the image should appear. I can download that will automatically open these emails?

    At soon AL

    Since it is a XP forum... I'm guessing that you are running Outlook Express?

    The following steps may be worth a try...

    Open Outlook Express and go to...

    Tools / Options / Security tab.

    Clear (clear) the box "block images and other external content in HTML e-mail" / apply / OK

    Also on the reading tab... Make sure that "Read all messages in plain text" is not checked.

  • My junk mail is to get term with mail that is sent using my email addresses. How can I stop this?

    My junk mail is to get term with mail that is sent using my email addresses. How can I stop this?

    I can't block emails from myself, I sometimes need to send things, so I got them at a later date.

    I know that I can view the source of the message, but I just want to stop this garbage that runs through for me.

    Can anyone help?

    There is not really a way to do it.  Just like you cannot block spam from your mailbox home - anyone can send you mail and anyone can use a false address 'return' that makes it look like it came from you.

    In fact, it is incredibly easy (only 10 letters typed) to send an e-mail that looks like it comes President @ whitehouse.gov.  That's how spammers do, because there is no check on email (I wish the people who invented the email 40 years ago had thought of that), but it is not just.

  • I have a HP laptop with vista that no longer starts.

    I have a HP laptop with vista that no longer starts. I get the initial screen of HP and can access the configuration, but after that, all I get is a black screen with a blinking cursor. I ran the diagnostic test on my hard drive and it happened, but my computer still does not start.

    Hi Shannon6836,

    1. Since when are you facing this problem?
    2. you remember to make changes to the computer before the question?

    3. are you able to boot in safe mode?

    See the methods mentioned below and check if that helps.

    Method 1:

    Start your computer in safe mode
     
    If you are able to start in safe mode, follow the steps mentioned below to complete the restore of the system:
     
    Note: System Restore does not affect personal files, such as e-mail, documents, or photos. You can only restore files that you have deleted if you have made backups of these files.
     
    Method 2:
     
    I suggest you to disconnect all devices external one except keyboard and mouse and try to start your computer and check if it helps.

    Method 3:

    I also suggest you perform a startup repair and check if this solves the problem.

    Follow the steps below:

    a. Please insert the Windows Vista DVD and restart the computer.

    b. when we are invited to press a key to boot from the DVD, please press enter or the SPACEBAR.
    c. choose your language settings, and then click Next.
    d. click repair your computer.
    e. Select the operating system you want to repair, and then click Next.
    f. in the System Recovery Options menu, click on the Startup Repair. Startup Repair can invite you to make choices as it tries to solve the problem, and if necessary, it may restart your computer, because it makes the repairs.
     
     
    If the Startup Repair tool is an option of recovering preinstalled on your computer:
    a. remove all floppy disks, CDs, and DVDs from your computer, and then restart your computer.

    Restart the computer

    b. do one of the following:
    i. If your computer has a single operating system installed, press and hold the F8 key as your computer restarts. You need to press F8 before the Windows logo appears. If the Windows logo appears, you need to try again by waiting until the Windows logon prompt appears, and then stop and restart your computer.

    II. If your computer has more than one operating system, use the arrow keys to select the operating system you want to repair, and then press and hold F8.
    III. in the display Advanced Startup Options , use the arrow keys to select repair your computerand press ENTER. (If repair your computer is not listed as an option, then your computer does not include startup as a preinstalled recovery option repair).
    IV. Select a keyboard layout, and then click Next.
    v. Select a username and enter the password, and then click OK.
    VI. in the System Recovery Options menu, click Startup Repair. Startup Repair can invite you to make choices as it tries to solve the problem and, if necessary, it may restart your computer, because it makes the repairs.
    Access the link below for more information on the Startup Repair:

    Startup Repair: frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/startup-repair-frequently-asked-questions

    Hope this information helps

  • When I'm on a video call with somone that my photo is still backwards down.how I fix this?

    When I'm on a video call with someone, that my photo is still backwards down.how I fix this?

    Hi Carolannjansson,

    Thanks for posting your query in Microsoft Community.

    I imagine the inconvenience that you are experiencing and will certainly help you in the right direction to solve the problem. However, I would be grateful if you could answer a few questions to refine the question in order to provide you with better assistance.

    1. What application you use to make a video call?
    2. Are all the device drivers and Windows updates are updated?
    3. What is the brand and model of your computer?
    4. It was working fine? If Yes, did you significant changes before the show?

    If you use Skype you can check the following thread and see if it helps you to solve the problem.

    The webcam image is upside down Skype.

    Get back to us with all the necessary information and the result of the proposed suggestion. We will be happy to help you.

    Kind regards

Maybe you are looking for