How to change the Rectangles with buttons

I'm working on this example that does not work correctly:

public class test extends Application
{

    private void init(Stage primaryStage)
    {

        Group root = new Group();
        primaryStage.setScene(new Scene(root));

        String pillButtonCss = DX57DC.class.getResource("PillButton.css").toExternalForm();

        // create 3 toggle buttons and a toogle group for them
        ToggleButton tb1 = new ToggleButton("Left Button");
        tb1.setId("pill-left");
        ToggleButton tb2 = new ToggleButton("Center Button");
        tb2.setId("pill-center");
        ToggleButton tb3 = new ToggleButton("Right Button");
        tb3.setId("pill-right");

        final ToggleGroup group = new ToggleGroup();
        tb1.setToggleGroup(group);
        tb2.setToggleGroup(group);
        tb3.setToggleGroup(group);
        // select the first button to start with
        group.selectToggle(tb1);

        //////////////////////////////////////////

        final VBox vbox = new VBox();

        final Rectangle rect1 = new Rectangle(300, 300);
        rect1.setFill(Color.ALICEBLUE);
        final Rectangle rect2 = new Rectangle(300, 300);
        rect2.setFill(Color.AQUA);
        final Rectangle rect3 = new Rectangle(300, 300);
        rect3.setFill(Color.AZURE);

        tb1.setUserData(rect1);
        tb2.setUserData(rect2);
        tb3.setUserData(rect3);

        group.selectedToggleProperty().addListener(new ChangeListener<Toggle>()
        {
            @Override
            public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle)
            {
                if (new_toggle == null)
                {
                    //rect.setFill(Color.WHITE);
                }
                else
                {
                    vbox.getChildren().addAll((Node[]) group.getSelectedToggle().getUserData());
                    //rect.setFill((Color) group.getSelectedToggle().getUserData());
                }
            }
        });


        ///////////////////////////////////////////


        HBox hBox = new HBox();
        hBox.getChildren().addAll(tb1, tb2, tb3);
        hBox.setPadding(new Insets(20, 20, 260, 20));
        hBox.getStylesheets().add(pillButtonCss);



        vbox.getChildren().add(hBox);
        //vbox.getChildren().add(rect);

        root.getChildren().add(vbox);
    }

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        init(primaryStage);
        primaryStage.show();
    }

    public static void main(String[] args)
    {
        launch(args);
    }
}


I want to create several Rectangles (or in which object or object) in which I want to store data. I want to spend the Rectangles (objects) that appear in front of the user by using the buttons. The example that I put in place does not work correctly. Can you tell me what is the right way to implement this?

REF javafx 2 - How to change the Rectangles with buttons - stack overflow

You have two problems:

User data that assign you to each button switches are a node, not a [Node]. Thus, the cast will fail on line 43.

When the selected toggle changes, you add another Rectangle to the vbox. You want to replace the rectangle that is in the vbox.

Try

vbox.getChildren () .setAll ((Node) group.getSelectedToggle () .getUserData ());

Tags: Java

Similar Questions

  • How to change the color of button

    I can create a newBrush to change the backgroundColor container, but I want to know how to change the color of the button?

    I posted here an example on how to change the color of the button here:

    Re: ScriptUI resource string: EditText: color

  • How to create the rectangle with rounded corners?

    How can I create a rectangle with rounded corners?

    Yes... I know x)
    but with the action script?

    I found: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html#draw RoundRect()

    Thank you

  • How to change the Source with EditText text in my Script?

    Here is my code, actually, the thing is I want to change my myEditText text in my control panel:

    function myScript(thisObj) {
              function myScript_buildUI(thisObj) {
                        var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);
    
                        res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\
                                  myEditText: EditText{text:'EditText text'},\
                                  myButton: Button{text:'Button Name'},\
                        }"
    
                        //Add resource string to panel
                        myPanel.grp = myPanel.add(res);
                        
                        
                        var texto = myPanel.grp.myEditText.text.value
                        
                        var btn =  myPanel.grp.myButton
                        
                        
                        
                        btn.onClick = function (){
                            
                            app.project.item(2113).layer("TXT 1").property("Text").property("Source Text").setValue = texto
                            
                            }
                        
                        
                        
                        
    
    
                        //Setup panel sizing and make panel resizable
                        myPanel.layout.layout(true);
                        myPanel.grp.minimumSize = myPanel.grp.size;
                        myPanel.layout.resize();
                        myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}
    
                        return myPanel;
              }
    
    
              var myScriptPal = myScript_buildUI(thisObj);
    
    
              if ((myScriptPal != null) && (myScriptPal instanceof Window)) {
                        myScriptPal.center();
                        myScriptPal.show();
                        }
              }
    
    
              myScript(this);
    

    Something like this should work:

    function myScript(thisObj) { 
    
      var textStr = "";
    
      function myScript_buildUI(thisObj) {
    
      var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);  
    
      res = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\
      myEditText: EditText{text:'EditText text'},\
      myButton: Button{text:'Button Name'},\
      }"
    
      //Add resource string to panel
      myPanel.grp = myPanel.add(res);
    
      // I added the next two lines.
      textStr = myPanel.grp.myEditText.text;
      myPanel.grp.myEditText.onChange =  myPanel.grp.myEditText.onChanging = textStringUpd;
    
      myPanel.grp.myButton.onClick = function (){
    
      app.project.item(2113).layer("TXT 1").sourceText.setValue(textStr);
      //or tell the script to change the soureText property of the currently selected layer (remove the two slashes from the line below and add them to the line above)
      //app.project.activeItem.selectedLayers[0].sourceText.setValue(textStr);
    
      }
    
      //Setup panel sizing and make panel resizable
      myPanel.layout.layout(true);
      myPanel.grp.minimumSize = myPanel.grp.size;
      myPanel.layout.resize();
      myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}
    
      return myPanel;
    
      }  
    
      var myScriptPal = myScript_buildUI(thisObj);
    
      // I added this function.
      function textStringUpd() {
    
      textStr = this.text;
    
      }
    
      if ((myScriptPal != null) && (myScriptPal instanceof Window)) {
                myScriptPal.center();
      myScriptPal.show();
      }
      }  
    
    myScript(this);
    

    I've added comments to indicate the changes that I made

  • You want to know why the icons displayed for only some bookmarks and how to replace the rectangle with an icon dotted valid in these cases.

    As explained in the question, some of the icons for sites appear only as a dotted rectangle. There are several favorites that have been imported from a html file and some of them have no icon showing on the list of bookmark or toolbar for Firefox, but they did it on the original browser where they wre imported. As a general rule, the icons 'fills' when each of the imported sites are visited some do not no matter how many times visited.

    I checked to make sure that the fonts and colors are chosen by the site server, so this isn't the problem.

    Although it is a function a little cosmetic (navigation works fine, just no icons), the icons site much faster recognition visually, making the browser it much faster and easier on the eye.

    Any help to fix this would be greatly appreciated for a user of Firefox "second-time-around."

    Firefox normally restore the favicon if use you this bookmark.

    See also:

  • How to change the Tiff with black background

    Hi all

    Here, I have attached test.tif illustrates normal file in windows Explorer, I'm open to change in photoshop, it opens with a black background can one has encountered this problem before?

    My thumbnails in windows Explorer

    img1.jpg

    My thumbnails of images in Photoshop CS2

    img2.jpg

    the original tiff image is here

    http://www.4shared.com/photo/fTznyfQr/test.html

    Thanks in advance

    concerning

    a you are the

    OK follow these steps to get rid black background

    1. open the image in Photoshop

    2 panel open layers

    3 hold down you control key and click on the Alpha (down in the Panel channel) channel, it will make a selection

    4. press the button DELETE and if you are prompted choose fill with 'White '.

    5. save

    Paul

  • How to change the "open with...". "to the zip folder?

    On the accident when opening a zip file with another program after going to the screen 'Open with', I didn't know that the small box has been checked for "Always use the selected program to open this type of file".

    Now, whenever I try to open a zip file, it doesn't with a zip on the RECORD, as he used to. It opens in whatever program is selected to open it with.

    I don't know how to make my zip files open in a zip folder.

    HELP Please!

    See http://www.winhelponline.com/articles/105/1/File-association-fixes-for-Windows-Vista.html

    Download the fusion and reg fix zip file.

    I hope this helps. Microsoft® Security MVP, 2004-2009

  • How to change the fonts with JS?

    Hello

    I have some files using the font that I want to replace it with another, but fail to understand how to do this with scripts. It's probably something very simple, but I can't go anywhere...

    for example, files indd containing character using [MyOldFont] styles like font family - > how I itterate through all objects using a few references to the old font and replace [MyNewFont] as the family of fonts by the script?

    Thank you

    K.

    In the character styles, you say:

    If (myCharacterStyle.appliedFont is "Fonts X")

    myCharacterStyle.appliedFont = 'Font Y')

    and cela for all character styles and paragraph styles probably as well. Then maybe do a find/replace on the document to catch local applications of the police:

    app.findGrepPreferences = app.changeGrepPreferences = null

    app.findGrepPreferences.appliedFont = "Fonts X"

    app.changeGrepPreferences.appliedFont = "Fonts Y"

    app.activeDocument.changeGrep)

    Peter

  • Satellite A100-727: how to change the config of media buttons?

    I have a Toshiba laptop Satellite A100 727 and it was these media buttons Nice on the left side of the key board.

    They are great, but I have no idea how to change the keys.
    I had put them to launch internet and exploited with mediaplayer, but after that I had to do reinstal windows, my harddisck crashed, functions on the buttons has changed, they start up the InterVideo WinDvd.

    Does one know how I can change the functions of the buttons?
    I read something about the tools of Toshiba, but I can't find them anywere.

    TYVM in advance

    Hello

    Using TOSHIBA button controls, you can set the key features. If you have it installed you can find the TOSHIBA controls icon in the Panel.
    You can also find if you open TOSHIBA help > Optimize.

  • Satellite A200 - 23 X: how to change the app assigned to buttons on the touchpad

    Dear friends,
    I have the Toshiba A200 23 X with Vista.
    I installed the Synaptics pointing for the touchpad device. I assigned in the 3 buttons, 3 different possibilities for that when I touch each of these buttons to start the appropriate application.

    The question is how to change the applications that I assigned?

    The first time, before fix, when I touch for example, the first button, a small window appears asking to attach a request, the same happened with the rest buttons 2.
    But now I want to change these apps that I have attached to these buttons, I know no way th.

    If anyone can help please.

    Thank you very much

    Hello

    I think you can change the settings of touchpad button in the properties of the touchpad.
    You can find properties of * Panel-> mouse-> device (last tab)-> settings button settings *.

    There are a few options. You must choose the option called Dual mode
    You will find the area where new applications could be affected.

    Concerning

  • How to change the size of taskbar buttons? I did everything that I've seen proposed in these pages, and nothing works.

    How to change the size of taskbar buttons?  I did everything that I've seen proposed in these pages, and nothing works.

    The buttons of programs open in the taskbar are tiny and square.  I want them to be of normal size (by default).  I have locked and unlocked the task bar.  I moved the "three vertical lines composed small points."  Nothing works.

    If you want to enlarge all the icons in the taskbar, and then increase the point size of buttons of legend to a larger number of advanced appearance settings.
    Follow these steps:

    1. click on start, Control Panel, personalization, window color and appearance.
    2. on the window color and appearance, click "Classic appearance open for more color options" (link below).
    3. in the box "Appearance settings", click on the button "Advanced".
    4. in the box "Advanced appearance" under "Item:" dropdown, choose "buttons".
    5 set your size
    6. click on the OK button.
    7 on the "Appearance settings" box, click on the button 'Aplly', wait.
    8. click the OK button if you are uncomfortable with the size to change, or just click on the "Advanced" button to set the size.

    I hope I could help

  • How to change the image of the button submit on forms of customer?

    Hi, I'm new here, in fact, we have not yet finished Eloqua implementation in society.

    I wanted to know how I can change the normal submit button in forms with a photo. Currently I tried to change the HTML form and replacing:

    of this

    < input id = "field3" value = "Submit" type = 'submit' style = "do-size: 100%;" Width: 100px; "height: 24 PX" / >

    for this

    " < input id ="field3"value ="Submit"type ="image"src =" http://shop.bodytrim.com.au/EDM/images/getyour.PNG " />

    Who should work on any normal Web site and working on Dreamweaver. But I don't see any change on the preview of the landing pages.

    Does anyone know what I might be missing here?

    Thank you

    Felipe

    Hi Felipe!

    Do you mean in the standard forms Eloqua Designer? When you create a form of E10 base you can change the Submit button by selecting the submit element in the Forms Designer, and then select the "Field settings" tab in the right column and select 'Choose the custom image' and download a new.

  • When checkboxing 'Use as Button' - how to change the color of overview?

    Smart form with the text: when checkboxing 'Use as Button' - how to change the color of overview?

    In the button shape properties panel, you will find a 'Normal' field, if you open the drop-down list you see the other two States, select and change the Fill/Color/Character...whatever you want.

    If you want to use the States for this button several times, I recommend to save the style or to create styles in the object Style Manager where you can also modify built-in three States: Normal, rollover and down.

  • How to change the highlight color, click the button image and text and sound.  are there packages of buttons for use in my project?

    How to change the highlight color, click the button image and text and sound. are there packages of buttons for use in my project?

    Hello

    Even if the point of things based Web links buttons created using them is of simple images. Captivate uses simple images. If you need to put your creative hat and not to let the fact that you see the word 'web' scared you somehow. An image is an image. Use on the web, use Captivate. Same case!

    If you change the properties of the button, you can activate the legend of success. Fix any sound that you like with the legend of success and it will play when you click the button. If you do not want to see the legend of success, delete the text and configure it as transparent.

    See you soon... Rick

    Useful and practical links

  • I recently bought an iPhone 6s I have loaded with my iTunes support information (old phone an iPhone 5). Problem is that I now have a replica on both phones I have an Apple ID - how to change the apple on the new ID

    I recently bought an iPhone 6s I have loaded with my iTunes support information (old phone an iPhone 5). Problem is that I now have a replica on both phones I have an Apple ID - how to change the apple on the new ID

    What do you mean by 'repetition '?

    You use two phones? Or did you give the old phone to someone else? If you use two phones, one ID on both Apple is probably than most people. Before you give or sell an iOS device, you must sign in iCloud in settings > iCloud and restore the device as good as new.

Maybe you are looking for

  • I cannot slide to unlock my iPhone 4S

    Why I can not unlock my iPhone 4S?

  • Realtek High definition audio not working not not on Satellite M100

    Ask a Satellite M100, which I shot the pre-installed Windows Vista Home edition to Windows XP Pro, for to use on our network of schools. After Installing Win XP SP2, I have no sound and the 'Device Manager' shows 'other devices' - device modem on hig

  • Re: Satellite P870 - how to change the keyboard backlight ON?

    We can see from the Web from Toshiba as Satellite P870 site (and other series like P850, L870, etc.) are NEW backlit keyboard. How to service this backlit? FN - Z does not work. Also, I do not see any symbol associated with this function on the keybo

  • Y410p SSD install?

    I recently bought a Y410p and an mSATA SSD, I hoped to install in it. I had assumed that there will be a pair of mSATA slots available, although he had no way of knowing since Lenovo does not document this information for consumers. From the opening

  • Update error. Failed to check the updates. Event ID 1001

    Update error. Failed to check the updates. I rebooted the PC and the Windows Update service (it is activated and automatic when you restart).  Is there an event ID 1001 in the event log that shows when I try to run WinUpdate. Can anyone help solve th