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;
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
add a comment |
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
Add an event handler for that anchorpane perhaps?
– Krishna Prashatt
Mar 26 at 5:48
add a comment |
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
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
java javafx fxml scenebuilder
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 a comment |
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 a comment |
4 Answers
4
active
oldest
votes
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");
add a comment |
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 Region
s; you simply need to add the style class it (styleClass="my-button"
).
add a comment |
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();
add a comment |
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)
You need my other post if you want to use this!
– fuggerjaki61
Mar 30 at 8:48
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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");
add a comment |
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");
add a comment |
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");
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");
answered Mar 26 at 6:26
Underscore_Underscore_
1
1
add a comment |
add a comment |
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 Region
s; you simply need to add the style class it (styleClass="my-button"
).
add a comment |
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 Region
s; you simply need to add the style class it (styleClass="my-button"
).
add a comment |
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 Region
s; you simply need to add the style class it (styleClass="my-button"
).
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 Region
s; you simply need to add the style class it (styleClass="my-button"
).
answered Mar 26 at 12:14
fabianfabian
56.1k11 gold badges54 silver badges75 bronze badges
56.1k11 gold badges54 silver badges75 bronze badges
add a comment |
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Mar 30 at 8:47
fuggerjaki61fuggerjaki61
14 bronze badges
14 bronze badges
add a comment |
add a comment |
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)
You need my other post if you want to use this!
– fuggerjaki61
Mar 30 at 8:48
add a comment |
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)
You need my other post if you want to use this!
– fuggerjaki61
Mar 30 at 8:48
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Add an event handler for that anchorpane perhaps?
– Krishna Prashatt
Mar 26 at 5:48