How do I change the color of an anchorpane from the controller class?How do I call one constructor from another in Java?How to get an enum value from a string value in Java?Fullscreen stage is not working properly in JavaFX 2.1?SceneBuilder2.0 does apply rules with color-lookupNullPointerException when trying to switch scenes in JavaFXReferencing JavaFX node from different controllerJavaFX, On Mouse EnteredHow to prevent maximized window from resizing when loading a new FXML in JavaFX?Setup .fxml file programmaticallyHow do I update the center node of a BorderPane using FXML Controller

Missing Contours in ContourPlot

What is this welding tool I found in my attic?

Why does the autopilot disengage even when it does not receive pilot input?

Chaining Dissonant Whispers via War Caster feat

nginx serves wrong domain site. It doenst shows default site if no configuration applies

download the bitcoin chain begining from a certain date

How to remove " 's" in a string?

Bob's unnecessary trip to the shops

What does "Fotze" really mean?

Why is the total number of hard disk sectors shown in fdisk not the same as theoretical calculation?

Can a continent naturally split into two distant parts within a week?

Do native speakers use ZVE or CPU?

Cubic programming and beyond?

Why doesn't the Lars family (and thus Luke) speak Huttese as their first language?

Rearranging the formula

Can I call 112 to check a police officer's identity in the Czech Republic?

Is killing off one of my queer characters homophobic?

How do Windows version numbers work?

Pre-1968 YA science fiction novel: robot with black-and-white vision, later the robot could see in color

How can I legally visit the United States Minor Outlying Islands in the Pacific?

Would letting a multiclass character rebuild their character to be single-classed be game-breaking?

Find values of x so that the matrix is invertible

When did the Roman Empire fall according to contemporaries?

What is the German equivalent of 干物女 (dried fish woman)?



How do I change the color of an anchorpane from the controller class?


How do I call one constructor from another in Java?How to get an enum value from a string value in Java?Fullscreen stage is not working properly in JavaFX 2.1?SceneBuilder2.0 does apply rules with color-lookupNullPointerException when trying to switch scenes in JavaFXReferencing JavaFX node from different controllerJavaFX, On Mouse EnteredHow to prevent maximized window from resizing when loading a new FXML in JavaFX?Setup .fxml file programmaticallyHow do I update the center node of a BorderPane using FXML Controller






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















For a GUI I'm making the minimize, maximize, close buttons similar to that of Spotify by using an anchorpane for each 'button'. I created the buttons via scenebuilder and they are loaded to the class via fxml. I can't figure out how to call a particular instance of an anchorpane in the controller class to change its background color when the mouse enters or exits.



public static Stage primaryStage;

@Override

public void start(Stage primaryStage) throws Exception
{

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

primaryStage.setScene(new Scene(root, 1280, 800));

...

this.primaryStage = primaryStage;

etc.


is how the UI class is set up



I expect the color of the anchorpane to change when the mouse enters the bounds, but as of now I have no idea how to call it.










share|improve this question






















  • Add an event handler for that anchorpane perhaps?

    – Krishna Prashatt
    Mar 26 at 5:48

















0















For a GUI I'm making the minimize, maximize, close buttons similar to that of Spotify by using an anchorpane for each 'button'. I created the buttons via scenebuilder and they are loaded to the class via fxml. I can't figure out how to call a particular instance of an anchorpane in the controller class to change its background color when the mouse enters or exits.



public static Stage primaryStage;

@Override

public void start(Stage primaryStage) throws Exception
{

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

primaryStage.setScene(new Scene(root, 1280, 800));

...

this.primaryStage = primaryStage;

etc.


is how the UI class is set up



I expect the color of the anchorpane to change when the mouse enters the bounds, but as of now I have no idea how to call it.










share|improve this question






















  • Add an event handler for that anchorpane perhaps?

    – Krishna Prashatt
    Mar 26 at 5:48













0












0








0








For a GUI I'm making the minimize, maximize, close buttons similar to that of Spotify by using an anchorpane for each 'button'. I created the buttons via scenebuilder and they are loaded to the class via fxml. I can't figure out how to call a particular instance of an anchorpane in the controller class to change its background color when the mouse enters or exits.



public static Stage primaryStage;

@Override

public void start(Stage primaryStage) throws Exception
{

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

primaryStage.setScene(new Scene(root, 1280, 800));

...

this.primaryStage = primaryStage;

etc.


is how the UI class is set up



I expect the color of the anchorpane to change when the mouse enters the bounds, but as of now I have no idea how to call it.










share|improve this question














For a GUI I'm making the minimize, maximize, close buttons similar to that of Spotify by using an anchorpane for each 'button'. I created the buttons via scenebuilder and they are loaded to the class via fxml. I can't figure out how to call a particular instance of an anchorpane in the controller class to change its background color when the mouse enters or exits.



public static Stage primaryStage;

@Override

public void start(Stage primaryStage) throws Exception
{

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

primaryStage.setScene(new Scene(root, 1280, 800));

...

this.primaryStage = primaryStage;

etc.


is how the UI class is set up



I expect the color of the anchorpane to change when the mouse enters the bounds, but as of now I have no idea how to call it.







java javafx fxml scenebuilder






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 5:44









Underscore_Underscore_

1




1












  • Add an event handler for that anchorpane perhaps?

    – Krishna Prashatt
    Mar 26 at 5:48

















  • Add an event handler for that anchorpane perhaps?

    – Krishna Prashatt
    Mar 26 at 5:48
















Add an event handler for that anchorpane perhaps?

– Krishna Prashatt
Mar 26 at 5:48





Add an event handler for that anchorpane perhaps?

– Krishna Prashatt
Mar 26 at 5:48












4 Answers
4






active

oldest

votes


















0














Solved it, had to set an fxid to the anchorpane and then initiate it in the controller class after an @FXML.



Kinda like this:



@FXML
Anchorpane someButton;

@FXML
public void makeButtonWhite(MouseEvent event)

someButton.setStyle("-fx-background-color: #ffffff");






share|improve this answer






























    0














    The most convenient way of doing this imho is using a stylesheet to assign the background.



    <AnchorPane xmlns:fx="http://javafx.com/fxml/1" stylesheets="@style.css">
    <children>
    <AnchorPane prefWidth="30" prefHeight="20" styleClass="my-button"/>
    </children>
    </AnchorPane>


    style.css (same directory as fxml)



    /* default style */
    .my-button
    -fx-background-color: blue;


    /* style when mouse is inside the region */
    .my-button:hover
    -fx-background-color: red;



    This allows you to easily add the style to multiple Regions; you simply need to add the style class it (styleClass="my-button").






    share|improve this answer






























      0














      the code you need for starting this must be the starting class



      public class Class extends Application 

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


      @Override
      public void start(Stage primaryStage)
      try
      // Load root layout from fxml file.
      FXMLLoader loader = new FXMLLoader();

      loader.setLocation(this.getClass().getResource("/Folder/File.fxml"));
      loader.setController(yourControllerClass());
      //only if you do something with the controller class afterwards
      YourControllerClass controller = loader.setController();

      Parent parent = loader.load();

      // Show the scene containing the root layout.
      Scene scene = new Scene(parent);
      primaryStage.setScene(scene);
      primaryStage.show();
      catch (IOException e)
      e.printStackTrace();









      share|improve this answer






























        0














        you know the code method in scenebuilder there you can set on mouse entered and exited for a button, a label etc. then if for example the button with the id "closeButton" and the OnMouseEntered "closeButtonOnEntered" and the OnMouseExited "closeButtonOnExited"
        this will be the code you need



        public yourcontrollerclass 
        @FXML
        Button closeButton;

        @FXML
        private void closeButtonOnEntered()
        //sets button red
        button.setStyle("-fx-background-color: #ff0000");


        @FXML
        private void closeButtonOnExited()
        //sets button your first color
        button.setStyle("-fx-background-color: transparent");




        this can be done with nearly every thing in sceneBuilder



        I hope i could help you(sorry for my bad english)






        share|improve this answer

























        • You need my other post if you want to use this!

          – fuggerjaki61
          Mar 30 at 8:48













        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350532%2fhow-do-i-change-the-color-of-an-anchorpane-from-the-controller-class%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Solved it, had to set an fxid to the anchorpane and then initiate it in the controller class after an @FXML.



        Kinda like this:



        @FXML
        Anchorpane someButton;

        @FXML
        public void makeButtonWhite(MouseEvent event)

        someButton.setStyle("-fx-background-color: #ffffff");






        share|improve this answer



























          0














          Solved it, had to set an fxid to the anchorpane and then initiate it in the controller class after an @FXML.



          Kinda like this:



          @FXML
          Anchorpane someButton;

          @FXML
          public void makeButtonWhite(MouseEvent event)

          someButton.setStyle("-fx-background-color: #ffffff");






          share|improve this answer

























            0












            0








            0







            Solved it, had to set an fxid to the anchorpane and then initiate it in the controller class after an @FXML.



            Kinda like this:



            @FXML
            Anchorpane someButton;

            @FXML
            public void makeButtonWhite(MouseEvent event)

            someButton.setStyle("-fx-background-color: #ffffff");






            share|improve this answer













            Solved it, had to set an fxid to the anchorpane and then initiate it in the controller class after an @FXML.



            Kinda like this:



            @FXML
            Anchorpane someButton;

            @FXML
            public void makeButtonWhite(MouseEvent event)

            someButton.setStyle("-fx-background-color: #ffffff");







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 6:26









            Underscore_Underscore_

            1




            1























                0














                The most convenient way of doing this imho is using a stylesheet to assign the background.



                <AnchorPane xmlns:fx="http://javafx.com/fxml/1" stylesheets="@style.css">
                <children>
                <AnchorPane prefWidth="30" prefHeight="20" styleClass="my-button"/>
                </children>
                </AnchorPane>


                style.css (same directory as fxml)



                /* default style */
                .my-button
                -fx-background-color: blue;


                /* style when mouse is inside the region */
                .my-button:hover
                -fx-background-color: red;



                This allows you to easily add the style to multiple Regions; you simply need to add the style class it (styleClass="my-button").






                share|improve this answer



























                  0














                  The most convenient way of doing this imho is using a stylesheet to assign the background.



                  <AnchorPane xmlns:fx="http://javafx.com/fxml/1" stylesheets="@style.css">
                  <children>
                  <AnchorPane prefWidth="30" prefHeight="20" styleClass="my-button"/>
                  </children>
                  </AnchorPane>


                  style.css (same directory as fxml)



                  /* default style */
                  .my-button
                  -fx-background-color: blue;


                  /* style when mouse is inside the region */
                  .my-button:hover
                  -fx-background-color: red;



                  This allows you to easily add the style to multiple Regions; you simply need to add the style class it (styleClass="my-button").






                  share|improve this answer

























                    0












                    0








                    0







                    The most convenient way of doing this imho is using a stylesheet to assign the background.



                    <AnchorPane xmlns:fx="http://javafx.com/fxml/1" stylesheets="@style.css">
                    <children>
                    <AnchorPane prefWidth="30" prefHeight="20" styleClass="my-button"/>
                    </children>
                    </AnchorPane>


                    style.css (same directory as fxml)



                    /* default style */
                    .my-button
                    -fx-background-color: blue;


                    /* style when mouse is inside the region */
                    .my-button:hover
                    -fx-background-color: red;



                    This allows you to easily add the style to multiple Regions; you simply need to add the style class it (styleClass="my-button").






                    share|improve this answer













                    The most convenient way of doing this imho is using a stylesheet to assign the background.



                    <AnchorPane xmlns:fx="http://javafx.com/fxml/1" stylesheets="@style.css">
                    <children>
                    <AnchorPane prefWidth="30" prefHeight="20" styleClass="my-button"/>
                    </children>
                    </AnchorPane>


                    style.css (same directory as fxml)



                    /* default style */
                    .my-button
                    -fx-background-color: blue;


                    /* style when mouse is inside the region */
                    .my-button:hover
                    -fx-background-color: red;



                    This allows you to easily add the style to multiple Regions; you simply need to add the style class it (styleClass="my-button").







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 26 at 12:14









                    fabianfabian

                    56.1k11 gold badges54 silver badges75 bronze badges




                    56.1k11 gold badges54 silver badges75 bronze badges





















                        0














                        the code you need for starting this must be the starting class



                        public class Class extends Application 

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


                        @Override
                        public void start(Stage primaryStage)
                        try
                        // Load root layout from fxml file.
                        FXMLLoader loader = new FXMLLoader();

                        loader.setLocation(this.getClass().getResource("/Folder/File.fxml"));
                        loader.setController(yourControllerClass());
                        //only if you do something with the controller class afterwards
                        YourControllerClass controller = loader.setController();

                        Parent parent = loader.load();

                        // Show the scene containing the root layout.
                        Scene scene = new Scene(parent);
                        primaryStage.setScene(scene);
                        primaryStage.show();
                        catch (IOException e)
                        e.printStackTrace();









                        share|improve this answer



























                          0














                          the code you need for starting this must be the starting class



                          public class Class extends Application 

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


                          @Override
                          public void start(Stage primaryStage)
                          try
                          // Load root layout from fxml file.
                          FXMLLoader loader = new FXMLLoader();

                          loader.setLocation(this.getClass().getResource("/Folder/File.fxml"));
                          loader.setController(yourControllerClass());
                          //only if you do something with the controller class afterwards
                          YourControllerClass controller = loader.setController();

                          Parent parent = loader.load();

                          // Show the scene containing the root layout.
                          Scene scene = new Scene(parent);
                          primaryStage.setScene(scene);
                          primaryStage.show();
                          catch (IOException e)
                          e.printStackTrace();









                          share|improve this answer

























                            0












                            0








                            0







                            the code you need for starting this must be the starting class



                            public class Class extends Application 

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


                            @Override
                            public void start(Stage primaryStage)
                            try
                            // Load root layout from fxml file.
                            FXMLLoader loader = new FXMLLoader();

                            loader.setLocation(this.getClass().getResource("/Folder/File.fxml"));
                            loader.setController(yourControllerClass());
                            //only if you do something with the controller class afterwards
                            YourControllerClass controller = loader.setController();

                            Parent parent = loader.load();

                            // Show the scene containing the root layout.
                            Scene scene = new Scene(parent);
                            primaryStage.setScene(scene);
                            primaryStage.show();
                            catch (IOException e)
                            e.printStackTrace();









                            share|improve this answer













                            the code you need for starting this must be the starting class



                            public class Class extends Application 

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


                            @Override
                            public void start(Stage primaryStage)
                            try
                            // Load root layout from fxml file.
                            FXMLLoader loader = new FXMLLoader();

                            loader.setLocation(this.getClass().getResource("/Folder/File.fxml"));
                            loader.setController(yourControllerClass());
                            //only if you do something with the controller class afterwards
                            YourControllerClass controller = loader.setController();

                            Parent parent = loader.load();

                            // Show the scene containing the root layout.
                            Scene scene = new Scene(parent);
                            primaryStage.setScene(scene);
                            primaryStage.show();
                            catch (IOException e)
                            e.printStackTrace();










                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 30 at 8:47









                            fuggerjaki61fuggerjaki61

                            14 bronze badges




                            14 bronze badges





















                                0














                                you know the code method in scenebuilder there you can set on mouse entered and exited for a button, a label etc. then if for example the button with the id "closeButton" and the OnMouseEntered "closeButtonOnEntered" and the OnMouseExited "closeButtonOnExited"
                                this will be the code you need



                                public yourcontrollerclass 
                                @FXML
                                Button closeButton;

                                @FXML
                                private void closeButtonOnEntered()
                                //sets button red
                                button.setStyle("-fx-background-color: #ff0000");


                                @FXML
                                private void closeButtonOnExited()
                                //sets button your first color
                                button.setStyle("-fx-background-color: transparent");




                                this can be done with nearly every thing in sceneBuilder



                                I hope i could help you(sorry for my bad english)






                                share|improve this answer

























                                • You need my other post if you want to use this!

                                  – fuggerjaki61
                                  Mar 30 at 8:48















                                0














                                you know the code method in scenebuilder there you can set on mouse entered and exited for a button, a label etc. then if for example the button with the id "closeButton" and the OnMouseEntered "closeButtonOnEntered" and the OnMouseExited "closeButtonOnExited"
                                this will be the code you need



                                public yourcontrollerclass 
                                @FXML
                                Button closeButton;

                                @FXML
                                private void closeButtonOnEntered()
                                //sets button red
                                button.setStyle("-fx-background-color: #ff0000");


                                @FXML
                                private void closeButtonOnExited()
                                //sets button your first color
                                button.setStyle("-fx-background-color: transparent");




                                this can be done with nearly every thing in sceneBuilder



                                I hope i could help you(sorry for my bad english)






                                share|improve this answer

























                                • You need my other post if you want to use this!

                                  – fuggerjaki61
                                  Mar 30 at 8:48













                                0












                                0








                                0







                                you know the code method in scenebuilder there you can set on mouse entered and exited for a button, a label etc. then if for example the button with the id "closeButton" and the OnMouseEntered "closeButtonOnEntered" and the OnMouseExited "closeButtonOnExited"
                                this will be the code you need



                                public yourcontrollerclass 
                                @FXML
                                Button closeButton;

                                @FXML
                                private void closeButtonOnEntered()
                                //sets button red
                                button.setStyle("-fx-background-color: #ff0000");


                                @FXML
                                private void closeButtonOnExited()
                                //sets button your first color
                                button.setStyle("-fx-background-color: transparent");




                                this can be done with nearly every thing in sceneBuilder



                                I hope i could help you(sorry for my bad english)






                                share|improve this answer















                                you know the code method in scenebuilder there you can set on mouse entered and exited for a button, a label etc. then if for example the button with the id "closeButton" and the OnMouseEntered "closeButtonOnEntered" and the OnMouseExited "closeButtonOnExited"
                                this will be the code you need



                                public yourcontrollerclass 
                                @FXML
                                Button closeButton;

                                @FXML
                                private void closeButtonOnEntered()
                                //sets button red
                                button.setStyle("-fx-background-color: #ff0000");


                                @FXML
                                private void closeButtonOnExited()
                                //sets button your first color
                                button.setStyle("-fx-background-color: transparent");




                                this can be done with nearly every thing in sceneBuilder



                                I hope i could help you(sorry for my bad english)







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Mar 30 at 8:48

























                                answered Mar 30 at 8:42









                                fuggerjaki61fuggerjaki61

                                14 bronze badges




                                14 bronze badges












                                • You need my other post if you want to use this!

                                  – fuggerjaki61
                                  Mar 30 at 8:48

















                                • You need my other post if you want to use this!

                                  – fuggerjaki61
                                  Mar 30 at 8:48
















                                You need my other post if you want to use this!

                                – fuggerjaki61
                                Mar 30 at 8:48





                                You need my other post if you want to use this!

                                – fuggerjaki61
                                Mar 30 at 8:48

















                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350532%2fhow-do-i-change-the-color-of-an-anchorpane-from-the-controller-class%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript