How to call a method written in Main class inside of a Controller? [duplicate]
This question already has an answer here:
Calling non-static methods from other classes
2 answers
Passing Parameters JavaFX FXML
8 answers
I have a login view, when I click the Sign In button I want my window to change its view. So, when I press the button, it calls the function inside of a controller that calls a function located inside of Main class.
Is there any way to achieve what I want? And is it necessary to have the same parent node in all fxml
files? (ex. AnchorPane, GridPane etc.)
I have looked to the code of login of JavaFX examples, but can't understand how they do it.
I also tried to change the scene, but the nodes inside of it behave like they don't belong to that window.
Main.java
public void changeWindow() {
Parent root = FXMLLoader.load(getClass().getResource("template/sampe.fxml"));
window = primaryStage;
window.setTitle("Some");
window.setResizable(false);
window.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
window.setScene(scene);
window.show();
}
LoginController.java
public void signInClicked() {
Main.changeWindow();
}
I want when button clicked, window changes its view.
java javafx stage
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 18 at 20:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Calling non-static methods from other classes
2 answers
Passing Parameters JavaFX FXML
8 answers
I have a login view, when I click the Sign In button I want my window to change its view. So, when I press the button, it calls the function inside of a controller that calls a function located inside of Main class.
Is there any way to achieve what I want? And is it necessary to have the same parent node in all fxml
files? (ex. AnchorPane, GridPane etc.)
I have looked to the code of login of JavaFX examples, but can't understand how they do it.
I also tried to change the scene, but the nodes inside of it behave like they don't belong to that window.
Main.java
public void changeWindow() {
Parent root = FXMLLoader.load(getClass().getResource("template/sampe.fxml"));
window = primaryStage;
window.setTitle("Some");
window.setResizable(false);
window.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
window.setScene(scene);
window.show();
}
LoginController.java
public void signInClicked() {
Main.changeWindow();
}
I want when button clicked, window changes its view.
java javafx stage
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 18 at 20:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of yourMain
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).
– fabian
Jan 18 at 20:54
add a comment |
This question already has an answer here:
Calling non-static methods from other classes
2 answers
Passing Parameters JavaFX FXML
8 answers
I have a login view, when I click the Sign In button I want my window to change its view. So, when I press the button, it calls the function inside of a controller that calls a function located inside of Main class.
Is there any way to achieve what I want? And is it necessary to have the same parent node in all fxml
files? (ex. AnchorPane, GridPane etc.)
I have looked to the code of login of JavaFX examples, but can't understand how they do it.
I also tried to change the scene, but the nodes inside of it behave like they don't belong to that window.
Main.java
public void changeWindow() {
Parent root = FXMLLoader.load(getClass().getResource("template/sampe.fxml"));
window = primaryStage;
window.setTitle("Some");
window.setResizable(false);
window.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
window.setScene(scene);
window.show();
}
LoginController.java
public void signInClicked() {
Main.changeWindow();
}
I want when button clicked, window changes its view.
java javafx stage
This question already has an answer here:
Calling non-static methods from other classes
2 answers
Passing Parameters JavaFX FXML
8 answers
I have a login view, when I click the Sign In button I want my window to change its view. So, when I press the button, it calls the function inside of a controller that calls a function located inside of Main class.
Is there any way to achieve what I want? And is it necessary to have the same parent node in all fxml
files? (ex. AnchorPane, GridPane etc.)
I have looked to the code of login of JavaFX examples, but can't understand how they do it.
I also tried to change the scene, but the nodes inside of it behave like they don't belong to that window.
Main.java
public void changeWindow() {
Parent root = FXMLLoader.load(getClass().getResource("template/sampe.fxml"));
window = primaryStage;
window.setTitle("Some");
window.setResizable(false);
window.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
window.setScene(scene);
window.show();
}
LoginController.java
public void signInClicked() {
Main.changeWindow();
}
I want when button clicked, window changes its view.
This question already has an answer here:
Calling non-static methods from other classes
2 answers
Passing Parameters JavaFX FXML
8 answers
java javafx stage
java javafx stage
edited Jan 18 at 20:58
Carlos Abraham
5131418
5131418
asked Jan 18 at 20:29
14DENDIK14DENDIK
46
46
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 18 at 20:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 18 at 20:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of yourMain
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).
– fabian
Jan 18 at 20:54
add a comment |
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of yourMain
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).
– fabian
Jan 18 at 20:54
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of your
Main
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).– fabian
Jan 18 at 20:54
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of your
Main
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).– fabian
Jan 18 at 20:54
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
I case you don't know how to combine the linked questions: The issue is that you do not have access to a instance of your
Main
class and try to call a non-static method. (Using just any instance wouldn't work btw.) The second duplicate describes ways of passing the application instance to the controller. I honestly do not know where the assumption that fxml files are limited in the node type comes from(You already know 2 different types are possible, what makes you think there's a limitation on some group?It's not even necessary to create nodes, but other objects cannot be added to a scene).– fabian
Jan 18 at 20:54