Get the text of a button when it is read as a node. VBox loop

I learn JavaFX, and it's just a small matter of programming.

I have 3 buttons in a VBox. And I want to apply the same 3 effects on all of the buttons after I put them in the Vbox. But when I use a loop and getChildren() on the VBox, they are returned as "nodes". I can't use Button.getText () to find the text of the button.

Is there a way I can getText to a node? Or maybe convert the current node to a button and get the text in this way?

VBox, vbox = new VBox();

Option 1 button = new Button ("first button");

Option 2 button = new Button ("Second button");
Option3 button = new Button ("display rules");

vbox.getChildren () .add (option1);
vbox.getChildren () .add (option2);
vbox.getChildren () .add (option3);

for (button end node: vbox.getChildren ())
{
button.setOnMouseEntered (new EventHandler < MouseEvent >)
{
@Override
public void handle (MouseEvent arg0)
{
button.setEffect (addEffect (Color.web("#53CFA6"),.8, 10));
}
});
button.setOnMouseExited (new EventHandler < MouseEvent >)
{
@Override
public void handle (MouseEvent arg0)
{
button.setEffect (addEffect (Color.web ("#FF6800"),.8, 10));
}
});

button.setOnMouseClicked (new EventHandler < MouseEvent >)
{
@Override
public void handle (MouseEvent arg0)
{
button.setEffect (addEffect (Color.web ("#E62800"),.8, 10));

To do button.getText)
Button; button.getText (work)


}
});
}

Hello user,.

You must have formatted your code correctly. See the forum guides for formatting codes.

To get the instance of the button, you need to do it safely
There are two ways to get the instance of the Button.

for (final Node button : vbox.getChildren()){
     Button b = null;
     if(button instanceof Button){
          b = button;
     }

     if(b != null){
          //Do your stuffs here
     }
}

Or you can even do like that too

for (final Node button : vbox.getChildren()){

     Button b =null;
     try{
          b = (Button) button; //casting the class
     }
     catch(ClassCastException e){
          e.printStackTrace();
     }

     if(b != null){
          //Do your stuffs here
     }
}

Thank you
Narayan

Tags: Java

Similar Questions

  • How get the text of each paragraph when a textStyleRange is made of texts to multiple paragraphs

    Hello

    Always on my account findText. The result is sometimes as a textStyleRange which contains the texts of multiple paragraphs. What is the best (and easy) way to get the text of each paragraph individually?

    Example: The result of an italic findText with the following extract gives me "saectur quatur? " " Ipsapidunte our" as a unique textStyleRange (correct) but I want to get the text of each paragraph.

    Is there a way to force the findText in the paragraphs and not those of them and if not, how to cut the textStyleRange in 2 texts?

    -----------------------

    Our Ipsapidunte and eumquosame derepre id ulparch iliquae offic tem faccusd aecaborrum, sequi aut doloreperi quaectem eatem faces very quam, con nullaccus repratur molorio enis modi sumquibus nostemquam and volorum facidunti nonseditati re a dolut dolorest ab idipitem saectur quatur?

    Our Ipsapidunte and eumquosame derepre id ulparch iliquae offic tem faccusd aecaborrum, sequi aut doloreperi quaectem eatem faces very quam, con nullaccus nostemquam repratur molorio enis modi sumquibus and re volorum facidunti nonseditati a saectur dolut dolorest ab idipitem quatur?

    There are two solutions:

    (1) you could be formatted every paragraph with formatting marks that you know doesn't exist anywhere else. In this way, each textStyleRange is guaranteed to end at the end of the paragraph.

    (2) you can access the entire first paragraph: myTextStyleRange.paragraphs [0]. I have not tested, but no doubt it works. You could also do a loop: paraLength = myTextStyleRange.paragraphs.length; for (i = 0; i< paralength;="" i++);="" mypara="myTextStyleRange.paragraphs[i];}">

  • Get the text of a button values

    Hi all

    I was wondering if there is a way, if a button is pressed, to capture the text of the button that has been pressed in the method fieldChanged at all?

    If your class does not extend ButtonField, of course then try to cast ButtonField throws a ClassCastException at you.

    If you use the code from this link, you must provide a method to make the code expose the text attribute, then call that instead.

  • get the text of a button on alertdialog

    Im trying to find how to discern what button is pressed in the alertdialog and I can't seem to find how do exactly... anyone knows?

    Hey,.

    You can use the selectedIndex property of the alert dialog class to get the index of the button that has been pressed - the first button showing would be 0 then 1 then 2 etc.

    Here's more information:

    http://www.BlackBerry.com/developers/docs/airapi/1.0.0/QNX/dialog/BaseDialog.html#SelectedIndex

    hope that things cleared up. Good luck!

  • Get the object already exist error when installing adobe reader software

    I can't install Adobe application programs on my Windows 7 computer.  I tried Adobe Reader XI, 5.6 Lightroom, Photoshop CC, etc.  All permits with the error "the object already exists.  I searched on the Adobe site to fix, and it is to remove the Crypto file.  However, it resulted with the same error.  How can I install Adobe Reader?

    Update of Windows KB2918614 to the Windows Installer Service because of similar problems with other software.  You might want to try to remove this update (it will be installed near the time you started to have this problem).  Restart and try again to install the Adobe application.

  • 1 word of the text, 1 colour, missing when gif

    Hello

    I have a PSD file. It has several layers with the same Illustrator file placed at different scales and positions.

    I placed the illustrator file once and duplicated that first mutiple layer before scaling and moving.

    The placed file includes 3 words of text and a vector logo. 1 Word is white.

    I have then open the PSD file in Fireworks and export each layout as a gif by turning the power on and off layers. The text is visible in 4 of the 6 exports. In one the white Word disappears whenever I select gif in "Preview image", it is not just the preview, it does not really save in gif. The gif palette shows no white border color or a lighter. As I said in the only case that one position.

    The layers are all exact replica except for scale.

    I deleted the layer in Phostoshop and made a new one with slightly different scale and position. Same result. I flattened the image in Phostoshop and which opened in Fireworks, same result.

    I saved as a bitmap of Phostoshop picture that opened in Fireworks, same result.

    What could happen to make white disappear just a gif?

    I downloaded the 5 gifs where the word should be visible, as you can see that the word "innocent" appears in 4 of them. In the second she disappears right on voversion to gif format. It is stored as 256 Adaptive that it takes to download in WordPress.

    It is visible in PDF, bmp, png, until what you're converting to gif format. The full PSD file is too big to download here. You can download it here http://gasolicious.com/questions/banners_2160x500.psd

    I use CS6. I have updated to Fireworks, without change. (I also tested in Fireworks CS5 and have the same problem)

    banners_2160x500_B.gif

    banners_2160x500_C.gif

    banners_2160x500_D.gif

    banners_2160x500_E.gif

    banners_2160x500_F.gif

    Post edited by: mgason. Add more images for clarity. Also note the Fireworks 5

    Unfortunately, I could not upload your PSD file successfully. Here are a few ideas:

    • You can save GIFs directly from Photoshop and Illustrator, without need of fireworks (if that helps).
    • Instead of a GIF file, you can try a very similar color format to PNG - 8, indexed.
    • I found that if I had white text selected on the canvas, when I opened a preview image and then played a little with the matte color (change none to white), I might accidentally get the text to disappear. Somehow, my actions were putting text fill to zero within the main interface.
    • I suggest you convert your text to text converted to outlines before exporting, to see if that solves the problem. However, it seems that you are trying a variety of techniques, including flattening of a bitmap, so it cannot help.

    If the GIF palette show you no white or lighter colors, first check the file itself: the white text is still visible? If this is the case, then maybe try manual adding color in the palette of GIF by using the ' Add ' button. Or you could try to save a palette from one of the GIFs and loading in the GIF that gives you problems (there is a drop down for it just above the drop-down list Format).

  • Call the base-dos .exe file, but how the input parameters and get the text on the screen of the BACK?

    Yes, I tried the similar topic before posting about this.

    I understand that we can use standard input of entrance of parameters of the System exec.vi, but still can not find an answer on "how to get the text on the screen of the BACK.

    1 seal of sw500912_2701test.exe is the exe of Basic-back , (change to rar .tar)

    2. double-click on the .exe, run this file. The first parameter is the rate band, the default value is 9600.

    3. setting the COM #.

    3.

    Can be useful to check that the command is actually being run. When the dos window opens is there any text?

    Try cmd /c "."

  • How to get the text enum I32 an uncontrollable (I / config terminal p side assets in the DAQmx screws)

    Hello

    I use DAQmx screw create clock.vi channel.vi and sample, they have entered (Terminal configuration of entry) and (active) both are I32 and have enum watch drop-down options. I want to use these text values to put in my excel file, but they give numerical codes associated with respective option. is it possible to get the text as it is.

    It is not an enum but I32 resembling enum...

    Help, please...

    Thank you

    In fact the active side is a control of the ring. Just a click and create a property for text.text ring node. This will give you the selected channel when the property node runs.

    I hope this helps.

  • How to get the text of a SystemPrompt (Cascades)

    Hello

    I've been struggling with this for a few hours now. I followed the example of "dialogues" on github, so I have successfully created a SystemPrompt (the dialog box that allows the user to enter text and accept / reject). Curiously, in this example there is no use of user text input. Do you know how to get the text in my QML? Here you have an example of code that I use:

    My QML:

    // Default empty project template
    import bb.cascades 1.0
    import bb.system 1.0
    
    // creates one page with a label
    NavigationPane {
        id: navigationPane
        Page {
            attachedObjects: [
                SystemPrompt {
                    id: prompt
                    title: qsTr("Enter a text for the label")
                    modality: SystemUiModality.Application
                    inputField.inputMode: SystemUiInputMode.Default
                    inputField.emptyText: "Label text..."
                    confirmButton.label: qsTr("Ok")
                    confirmButton.enabled: true
                    cancelButton.label: qsTr("Cancel")
                    cancelButton.enabled: true
                    onFinished: {
                        if (result == SystemUiResult.ConfirmButtonSelection) {
                            lab1.text = ????? // Here is where I don't know what to do
                        }
                    }
                }
            ]
    
            Container {
                layout: StackLayout {}
    
                Label {
                            id: lab1              text: "Label text"
                    objectName: "lab1"
                    textStyle.base: SystemDefaults.TextStyles.TitleText
                    horizontalAlignment: HorizontalAlignment.Center
                }
    
                Button {
                    text: "Update label"
                    horizontalAlignment: HorizontalAlignment.Center
                    topMargin: 150.0
                    onClicked: {
                        //_appUi.editLabel();
                        prompt.show();
                    }
                }
            }
        }
    }
    

    Be sure to add this in your .cpp file or all of app:

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    

    and don't forget to include them in your app .cpp file (probably not all are needed, but just in case I leave here for the moment):

    qmlRegisterType("bb.system", 1, 0, "SystemUiButton");
        qmlRegisterType("bb.system", 1, 0, "SystemUiInputField");
        qmlRegisterType("bb.system", 1, 0, "SystemToast");
        qmlRegisterType("bb.system", 1, 0, "SystemPrompt");
        qmlRegisterType("bb.system", 1, 0, "SystemCredentialsPrompt");
        qmlRegisterType("bb.system", 1, 0, "SystemDialog");
        qmlRegisterUncreatableType("bb.system", 1, 0, "SystemUiError", "");
        qmlRegisterUncreatableType("bb.system", 1, 0, "SystemUiResult", "");
        qmlRegisterUncreatableType("bb.system", 1, 0, "SystemUiPosition", "");
        qmlRegisterUncreatableType("bb.system", 1, 0, "SystemUiInputMode", "");
        qmlRegisterUncreatableType("bb.system", 1, 0, "SystemUiModality", "");
        qRegisterMetaType("bb::system::SystemUiResult::Type");
    

    Thank you very much

    If you look very carefully by the docs, you'll trip over https://developer.blackberry.com/cascades/reference/bb__system__systemprompt.html#inputfieldtextentr...

    So, replace your? with inputFieldTextEntry() and you will get the text you need.

  • Get the text in the Edit field

    Hello

    In my Application, I add a check box and a label field and a field change a grid field Manager. Then this network domain manager, I add several times in Vertical field Manager. So it's looking like list of items. Now, when I checked the box five, trying to get the text of the corresponding edit field.

    This is the code for the domain network manager:

    int c[] = {screenWidth/6, (screenWidth)/3, (screenWidth)/2};
            gm = new GridFieldManager(c, Manager.VERTICAL_SCROLL);
            Logger.out("Grocery", "Here it is coming"+i);
            cbfChecked = new CustomCheckBoxField();
            cbfChecked.setChangeListener(new FieldChangeListener()
            {
                public void fieldChanged(Field field, int context)
                {
                    if(checked[i] == false)
                    {
                        checked[i] = true;
                    }
                    else if(checked[i] ==  true)
                    {
                        checked[i] = false;
                        Logger.out("Grocery", "It is UnChecked" +checked[i]);
                    }
                }
            });
            gm.add(cbfChecked);
            Logger.out("Grocery", "Adding first Label Field");
            LabelFieldCustom lfFrom = new LabelFieldCustom((String) m_vtrItems.elementAt(i),Color.BROWN,FONT_FAMILY_0_SF_AS_16,Field.FIELD_LEFT);
            gm.add(lfFrom);
            Logger.out("Grocery", "Adding second Label Field");
            efcAmount = new EditFieldCustom(Bitmap.getBitmapResource("dob_text_box.png"), 25);
            efcAmount.setMargin(new XYEdges(30, 0, 0, 0));
            gm.add(efcAmount);
            return gm;
    

    Here I add the grid domain manager several times:

    for (int i = 0;i < m_vtrItems.size();i++)
            {
    
                vfm.add(getRow(i));
                vfm.add(new SeparatorField(SeparatorField.NON_FOCUSABLE));
    
            }
    

    Here is the snapshot of my screen:

    Please help me.

    You can access the field by index (prone to errors if).
    or you could save your fields in a data structure, such as a hash table, with the checkboxfield as key to the editfield as value.
    or...

  • I have a form in which the text area can be developed to accept more text, but the text does not appear on the printed copy.  How can I get the text to print?

    I have a form in which the text area can be developed to accept more text, but the text does not appear on the printed copy.  How can I get the text to print?

    Hi robinm6200,

    Make sure that you have selected 'Document and annotations' under 'Comments and forms' when printing.

    Kind regards

    Nicos

  • How to get the text in a dynamic text field?

    Hello

    I would like to get the text in a text field I have on stage and put it into a string. I do this because I don't don't want to use the table to store each letter I click. Is this possible?

    Concerning

    you don't know.  You can use the text property of your textfield object and store that value in a variable.

    You can use a click on a button to trigger this code or change event of the textfield or any number of other triggers.

  • get the text of the paragraph?

    Hi all

    How to extract text perticular single paragraph object.  I've searched the forums and get the paragraph.texts.itemByRange () methods, but I don't know how to use this method to get the text of perticular and I want to delete the text of the paragraph.

    I would appreciate for any help to...

    Kind regards

    Imagine

    Sorry, that makes it clearer.

    1 itemByRange is useful only when you have the beginning and the end of the range in the form of numbers. What, where you plan to do? Ask in a dialog box from where to where to remove them? The lines "the user has selected" text are just a choice, and you can manipulate that immediately. There is no reason to convert it to a format usable for itemByRange first.

    2. at this stage in your stage of learning, should not focus on Getting the * thing at work, rather than focusing on writing elegant, easy to manage, short but not darkened code? All of you who have no meaning if your script does not run.

  • How to get the text of TextEditBox on Panel

    Hi all

    I would ask you, what should I use when I want to get the text of TextEditBox. I have the observer, who listens to the chages (when the user hits enter, the Update method of the observer is called). The only thing I don't know is how to get the text, which was placed in the text edit box. I know that this observer of the dialog box, GetTextControlData method, but I sign...

    THX

    Hi Ondrej

    You can get the text using the ITextControlData interface. Like this:

    InterfacePtr iCtrlView (this, UseDefaultIID());
    if(!iCtrlView) break; put some say message
    InterfacePtr iTextData (iCtrlView, UseDefaultIID());
    if(!iTextData) break; put some say message
    PMString theString = iTextData-> GetString()

    Concerning

    Bartek

  • Cannot get the text in the field description flex

    Hi all

    I try checking if a field flex text value contains anything or not. IE, this flex field is a mandatory field and I need to check when running.
    But I can't get the text value of the descriptive flex field written by the user at run time.

    OADescriptiveFlexBean oadescriptiveflexbean1 = (OADescriptiveFlexBean) webBean.findIndexedChildRecursive ("PerfRatingFlex");
    If (oadescriptiveflexbean1! = null & & oadescriptiveflexbean1.isRendered ())
    {
    String revision = (String) oadescriptiveflexbean1.getAttributeValue ("ATTRIBUTE12");
    }

    I can't retrieve any value of variable revizeNedeni. I tried a few combinations of such use, and I searched the forum for this problem and I tried these suggestions. But I failed.
    Could someone give me some examples of specific code for this?

    Hello

    PerfRatingFlex9__xc_ is not FDF Id field, your identifier is PerfRatingFlex9, just try it with this, you will get the data

    in the page source view, PerfRatingFlex9__xc_ and PerfRatingFlex9, both displayed against the identification sticker, if you search with "PerfRatingFlex9" you will find the same thing against "id =" tag after the prompt of the FDF field.

    thanx

    Pratap

Maybe you are looking for

  • Pavilion Slimline s5780t: compatibility Windows 10

    Hello I have a friend with the model listed above. It was recently upgraded to Windows 10 (translation: Microsoft forced the upgrade on him without his consent). His PC was working fine before the upgrade, but since then, he has been presenting all k

  • External monitor satellite 4030 CDT

    Hi Please helpI have a Satellite 4030 CDT running windows 98 with a trident cyber9525DVD W98 driver/video card (22) PCI/AGP.I bought a LCD TV and I would like to use it as an external monitor.When I use the Fn + F5 to switch I do not get a signal on

  • BIOS password help

    Folio 13-2000 Disabled system [59472296]

  • E3000 to work with the modem configuration cable of Verizon FIOS actiontec / router

    Hi all, I read knowledgebase Article ID: 3733, which seems to me on the right track, but the menu router screens listed do not correspond to the screens of the E3000. I have a FIOS cable modem / router in the basement I should keep since she animates

  • RV042 stopped working

    Hello I have the following problem: My rv042 stopped working after about two weeks.  The configuration looks like this: Belkin Wireless Pre - N in bridge to port 1 mode -RV042 1 computer connected to port 2 -Cable modem Internet -DSL Modem in bridge