stage without bar (javafx) - java

I want to make a window like eclipse loading by javafx without the bar ,
what I can do !!?
this loading screen

Just use this line. You won't see any title bar in your application.
stage.initStyle(StageStyle.UNDECORATED);

hihi,
you could try this:
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.initStyle(StageStyle.UNDECORATED);
scene.setFill(Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}

Related

Javafx how to load button animation then execute method

I need help to load first the animation of the button then execute the onAction method because when I click the button, the animation of the button is delayed... How to fix it?
here is the sample code:
public void viewStage(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Stage.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.getIcons().add(new Image("/img/Stage.png"));
stage.setTitle("New Stage");
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception e){
System.out.println(e);
}
}

Java FX crash when changing scene

I'm trying to make a POS using javaFX but whenever I try to change the scene it keeps crasing. Any ideas of how to fix?
Main class: https://pastebin.com/4bspSL9N
SceneManager: https://pastebin.com/SU99DVgf
OutputHelper.log() is just a system.out.println()
output log: https://pastebin.com/GZTPRgNp
You have not initialized your primaryStage in the SceneManager. Try adding this.primaryStage = primaryStage; in your setup method.
Try this in your SceneManager class:
public static void loadScreen(Parent parent) throws IOException {
Platform.runLater(() -> {
Stage stage = new Stage(StageStyle.UNDECORATED);
// stage.setMaximized(true);
stage.setFullScreen(true);
// stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
Scene scene = new Scene(parent);
stage.setScene(scene);
stage.show();
});
}
Then to Load new screen use it like :
String Screen = "YourScreen.fxml";
Parent root = FXMLLoader.load(getClass().getResource(Screen));
SceneManager.loadScreen(root);
hope this will help
This a bit late to the party but we will post for posterity
We name all our Anchor Pane's so we know who they are ie mynamePane
Then when you click a Button to go somewhere you only need to know where you are and where you want to go
private void doSEARCH() throws IOException{
stage = (Stage)searchPane.getScene().getWindow();// pane you are ON
viewtxPane = FXMLLoader.load(getClass().getResource("tableview.fxml"));// pane you are GOING TO
Scene scene = new Scene(viewtxPane);// pane you are GOING TO
scene.getStylesheets().add(getClass().getResource("checkbook.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Check Book Transactions");
stage.show();
stage.sizeToScene();
stage.centerOnScreen();
}

JAVAFX secondary panels

Hi guys a little programmer java Swing and I'm trying a new technology like JavaFx just that I just can not figure out how to make operations for navigation between views, in particular.
How can I replace a main view on the stage? for example I have a view that I associate with the calback start method in the scene in the following way
#Override
public void start(Stage primaryStage) {
vistaPrincipale.load();
Scene scene = new Scene(vistaPrincipale.getRoot());
primaryStage.setScene(scene);
primaryStage.show();
}
and during the execution of the program I would like to change the view one with the view two, only that I could not really understand how I did not even find enough material to solve the problem, in swing it was enough to change the frame content bread
another problem that I have encountered is to launch a secondary panel like a jdialog in swing, I solved this problem by creating a new stage and using it in the following way, but to be honest it really seems like a very bad solution
public class InfoAutori {
private static final Logger LOGGER = LoggerFactory.getLogger(InfoAutori.class);
private Stage stage;
public void init(){
FXMLLoader load = new FXMLLoader();
Parent root = new AnchorPane();
try {
root = load.load(getClass().getResourceAsStream("InfoAutori.fxml"));
} catch (Exception e) {
LOGGER.error("Si e' verificato un errore del tipo: " +
e.getLocalizedMessage());
e.printStackTrace();
}
stage = new Stage();
Scene scene = new Scene(root);
stage.setScene(scene);
}
public void visualizza(){
stage.showAndWait();
}
}

JavaFX switching scenes

I've been trying to make my application to switch between scenes. Here is a copy of part of the code. The credits scene simply has a back button which should return me to the main scene.
When I try to click on credits button on main scene it is becoming white a white screen. I believe that there is a better way to solve this problem could you give me some advices ?
public class Application {
public static void main(String[] args) {
javafx.application.Application.launch(GUI.class);
}
}
public class GUI extends Application {
#Override
public void start(Stage primaryStage) {
Scene mainScene, creditsScene = null;
mainScene = getMainScene(primaryStage, creditsScene);
creditsScene = getCreditsScene(primaryStage, mainScene);
primaryStage.setTitle("Test application");
primaryStage.setScene(mainScene);
primaryStage.show();
}
private Scene getMainScene(Stage primaryStage, Scene creditsScene) {
final Button credits = new Button("Credits");
credits.setOnAction((ActionEvent e) -> {
primaryStage.close();
primaryStage.setScene(creditsScene);
primaryStage.show();
});
VBox x = new VBox(50);
x.setAlignment(Pos.CENTER);
x.getChildren().addAll( run, displayInfo,
label1, displayInfo, textField, submitName, credits, exit);
//scene size
Scene scene = new Scene(x, 650, 900);
return scene;
}
private Scene getCreditsScene(Stage primaryStage, Scene main) {
final Button back = new Button("Back");
back.setOnAction((ActionEvent e) -> {
primaryStage.setScene(main);
});
VBox x = new VBox(50);
x.getChildren().addAll(back);
Scene credits = new Scene(x, 650, 900);
return credits;
}
Try to switch order of strings:
mainScene = getMainScene(primaryStage, creditsScene);
creditsScene = getCreditsScene(primaryStage, mainScene);
here you pass to getMainScene null.

How to open another window in JavaFX 2?

I have made a simple JavaFX application, but I would like the main window to open a secondary window when the user clicks a button.
What would be the simplest way to accomplish this?
Button b = new Button();
b.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent e) {
Stage stage = new Stage();
//Fill stage with content
stage.show();
}
});
try this
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXML.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
((Node) (event.getSource())).getScene().getWindow().hide();
} catch (Exception e) {
e.printStackTrace();
}

Categories

Resources