Align text vertically on a button

I want to vertically center text in a button.

Here is my code:

var playTextFormat:TextFormat = new TextFormat();
playTextFormat.color = 0xAA0000;
playTextFormat.size = 18;
playTextFormat.italic = false;
playTextFormat.align = TextFormatAlign.CENTER;

var playText:TextField = new TextField();
playText.text = "Play";
playText.setTextFormat(playTextFormat);

var playButton:Button = new Button();
playText.width = playButton.width;
playText.height = playButton.height;
playButton.addChild(playText);
playButton.addEventListener(MouseEvent.CLICK, playWindow);
playButton.x = (vStageWidth - playButton.width)/2;
playButton.y = (vStageHeight - playButton.height)/2;

I have centered horizontally, but not vertically.

How can I do?

Yes you can. There is a setTextFormatForState() method that can help you with that. more details can be found here:

http://www.BlackBerry.com/developers/docs/airapi/1.0.0/QNX/UI/buttons/LabelButton.html#setTextFormat...

hope that helps. Good luck!

Tags: BlackBerry Developers

Similar Questions

  • How to align text vertically?

    I have the text of the entry box and the size is width: 200 and Hight: 150. I need align the text vertically Center using action script.

    Please help me!

    Thank you

    Jafy

    Here is an example of centering. With respect to the XML, etc, I guess that's another topic - for a new thread, he is.

    var textContainer:Sprite = new Sprite();var g:Graphics = textContainer.graphics;g.beginFill(0x80FF00);g.drawRect(0, 0, 400, 300);g.endFill();
    
    var format:TextFormat = new TextFormat("Arial", 20, 0x0000FF, "bold");
    
    var textField:TextField = new TextField();textField.autoSize = TextFieldAutoSize.LEFT;textField.defaultTextFormat = format;textField.text = "This is the text!\nAnd it is centered\nall over the place";textField.x = (textContainer.width - textField.width) * .5;textField.y = (textContainer.height - textField.height) * .5;
    
    textContainer.addChild(textField);addChild(textContainer);
    
  • align text vertically?

    Hey there!

    do you know how to align the text vertically?

    I have a text box that is up to 400 and there is a single line of text going in what to be centered, so there is the same amount of space at the bottom and the top. the text can be changed in the amount of lines, so I need to have a way of centering it always.

    You cannot Center the text vertically within the field - instead, you move the field to focus in the space you need. You can use the textHeight field property to get the height of the text, in pixels.

    As an example - say you want to center the text between y = 200 and y = 500:

    myText.y = 200 + ((300-myText.textHeight) *. 5);

  • Align the text field and a button.

    Hi all

    I use Oracle APEX 5.0.1.

    I tried to create a search page that contain a text field and a button.

    But I can't align the text field and button, so they can have the same top position.

    Could someone please help me solve this problem?

    APEX-ARE-Search.jpg

    Thank you and best regards,

    Troy.

    Hello.

    Have you tried to add a css attribute to the button? like: style = "top: 4px;

    Concerning

  • Vertical text align text in AppleScript.

    Hi, can't seem to get the syntax correct vertically align the text in the text block for AppleScript.

    Thank you

    Joe

    Hey Joe,

    Can you please try this, I hope that expect you that?

    tell application "Adobe InDesign CS4"
         set myVerticalJustification to center align
         set vertical justification of text frame preferences of selection to myVerticalJustification
    end tell
    

    THX

    csm_phil

  • Center text vertically on a line

    I need to figure out how to center the text vertically.check it out to see what I'm talking... I want to center the text "grind time" to be centered with the media player and add to Cart button www.l3thalproductions.com/productpage.html

    l3thalbeats wrote: worked fine on my flash media player, but does not give me the possibility to align the absolute middle on the add to Cart button

    Your images appear to be included in the following twoand tags:

    http://i236.Photobucket.com/albums/ff11/sulphurtors22/add-to-Cart-button.jpg"alt ="PayPal - the safer, easier way to pay online how!"border ="0"/ >

    https://www.PayPal.com/en_US/i/SCR/pixel.gif"width ="1"height ="1">

    You cannot align these tags using align or valign attributes.  Him are deprecated attributes.

    Try a style attribute and align the images with a pair of property: value - namely, vertical-align: middle

    The attributes are entered as followsand

    TAG: http://www.w3schools.com/tags/tag_img.asp 

    TAG:  http://www.w3schools.com/tags/tag_input.asp

  • best way to align text in the fw

    What is the best way to align text in Fireworks?  I tried to use the Alignment tab, but it does not work too good for me.  is there a better way to do it?

    To align text objects vertically to each other, try selecting them, and then selecting "Align top edge", with "from Web" off. (I don't know why, but "Center vertical alignment" and "align bottom" both seem to lead to imbalances.) Pretty weird behaviour, in fact). If this does not work, then try using leaders and guides, as described in my first answer.

    Spread text objects, try the first and the last objects ('Home' and 'Contact') regarding their positioning slices, and then select all text objects and choose "distribute horizontal center" to evenly space items remaining in-between (with 'to Web"off). If this does not work, then just eyeball it: use the arrows to adjust the level of each text object position until it looks centered.

    This is a perfect example of why Fireworks must support the selection of an object 'key '. If that were the case, I'll tell you to select each slice individually, and text object to choose the slice as a "key object" and then align horizontal and vertical centers. Unfortunately, this is not an option here.

    Seriously, however, please take the time to be accurate during the validation of future issues. If all goes well, I have given you a lot of ideas and leads on how to solve this problem.

  • Right-aligned text entry area

    I create an interactive demonstration that requires the user to enter text in

    a field. The standard text for the field simulated entry is

    right-justified. Is it possible to text in a right-aligned text

    input box?

    Darin

    Hi Darin,

    Create a button and submit them to the subject, is paused the slide. You wonder if you want to post? Or you want to just check if something was entered? In both cases, you can use the variable associated with the TAW, that is the reason why I made for the blog. If you have any questions, will try to help.

    Lilybiri

  • How to justify text vertically in a TextInput

    So I have a simple question: How can justify you text in a TextInput vertically?

    Ah ha. Well. I thought that I answered all the permutations of your question, but I just covered in permutations of what you might have meant by "textInput" and not you may have a sense of 'justify '. So when talking about text, justify is commonly known as meaning align the left and right margins of the textfield object. to illustrate, I have "justified" this text box. But if its center the text vertically you wanted to do, I don't think it's possible with the textInput component.

    The closest I can find in the TextInput styles is "textPadding", which allows the padding between the text and the border of the element.

    I think you would be better, if you really was missing the TextInput component watch 48 pixels maximum, would be to use a regular TextInput component (22 pixels high) borderless (whether through counting or style) and then place the component where you like it and draw the border yourself.

  • multiple lines of text on a command button

    Is it possible to get multiple lines of text on a command button.  Instead of a large button with the text "start the Test System".  I would like a big button with 3 lines.

    Beginning

    Test

    System

    If you change the label of the button control in IUR editor you can split the text into lines with Ctrl + Enter.

    If you programmatically set the label, "\n" code integration in the text of the label.

    Both methods work for all types of control, not only for the command buttons.

  • How to draw the text vertically?

    Hello friends,

    I want to write some text vertically. I use all the DrawStyle to do this but I have no success...  Please help me to write text vertically.

    See picture for more clearification I want to draw.

    Kind regards

    Krishan Kant

    Hi key_key,

    Try this code

    int thetaFixed = Fixed32.toFP (90);
            
    int cell_11 = Fixed32.cosd (thetaFixed);
    int cell_12 = - Fixed32.sind (thetaFixed);
                        
    int cell_21 = Fixed32.sind (thetaFixed);
    int cell_22 = Fixed32.cosd (thetaFixed);

    int [] transform = new int [] {cell_11, cell_12, cell_21, cell_22, 0, 0};
    Font myFont = Font.getDefault () .derive (Font.BOLD, 17, Ui.UNITS_px, Font.ANTIALIAS_STANDARD, 0, transform);
            
    LabelField lab = new LabelField ("Hello");
    lab.setFont (myFont);
            
    Add (Lab);

    You can also set this font for the graphics object in any method of paint if you need.

    Thank you.

  • How to align text

    something that I always found it frustrating is not able to align text properly without first creating outlines. Here's what I mean, black 0 is always text and is aligned to the center circle, however he is biased, the Red 0 is described and properly aligned at the Center. any way around this?

    01.jpg

    Hi Dr. Tyrell,

    You must use a contour also direct Effect

    Select the text, then go to Effects-> Path-> outline object

    and in editing-> preferences-> general use Preview limits lights

    Now the Bounding Box fits on the text and you will be able to align the text perfectly.

  • How to view the text onto an interactive button in Indesign CC?

    How to view the text onto an interactive button in Indesign CC?

    I'm doing my map.

    I am now able to link a button in my card to a website url, but what I really want is a way to make the text appear next to a button, it shows what kind of construction is by turning over with the mouse.

    One?

  • I need to select all the blocks of text in a document and align text blocks in the back pages left frame margin and the text in the pages front to the right margin.

    Hello

    Am new to Java script.

    Can someone help me out here, I need to select all the blocks of text in a document and align text blocks in the pages back to the left margin frames and text in pages recto at the right margin.

    Thank you
    Harish

    Hi Harish,

    Try this.

    var doc =app.activeDocument,
        _pages = doc.pages;
    doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
    for(var i =0;i<_pages.length;i++)
    {
            txfms = _pages[i].textFrames.everyItem().getElements();
            for(var j =0;j
    

    Kind regards

    Cognet

  • Is it possible to use tabs to align text right in Muse, as you can in InDesign?

    Can I use tabs to align text right in Muse, as you can in InDesign?
    I have a beauty treatment, followed of a prize and I want to right-align the price, keeping the treatment to the left of the text box.

    Thank you!

    Tabs are not supported by the real browsers.

Maybe you are looking for