{"id":15056168,"url":"https://github.com/marcotrombino/fxrouter","last_synced_at":"2025-04-10T04:06:51.263Z","repository":{"id":82032326,"uuid":"114307437","full_name":"Marcotrombino/FXRouter","owner":"Marcotrombino","description":"A simple JavaFX router to switch between application scenes","archived":false,"fork":false,"pushed_at":"2017-12-28T15:09:23.000Z","size":32,"stargazers_count":37,"open_issues_count":2,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T04:06:45.646Z","etag":null,"topics":["java-gui-application","javafx","javafx-library","javafx-multiple-scenes"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Marcotrombino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-14T23:53:11.000Z","updated_at":"2024-12-01T13:39:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"1da81c48-c1b3-4900-8f28-da477d89a62e","html_url":"https://github.com/Marcotrombino/FXRouter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marcotrombino%2FFXRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marcotrombino%2FFXRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marcotrombino%2FFXRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marcotrombino%2FFXRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Marcotrombino","download_url":"https://codeload.github.com/Marcotrombino/FXRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154984,"owners_count":21056543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java-gui-application","javafx","javafx-library","javafx-multiple-scenes"],"created_at":"2024-09-24T21:48:37.312Z","updated_at":"2025-04-10T04:06:51.238Z","avatar_url":"https://github.com/Marcotrombino.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/Marcotrombino/FXRouter/blob/master/fxrouterlogo.png\"\u003e\u003c/p\u003e\n\n# FXRouter\n[![release](http://github-release-version.herokuapp.com/github/Marcotrombino/FXRouter/release.svg?style=flat)](https://github.com/Marcotrombino/FXRouter/releases/latest)\n[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\nA simple JavaFX router to switch between application scenes\n\n[Example](#example)\n\n## Download\nGet latest release [here](https://github.com/Marcotrombino/FXRouter/releases/latest)\n\n## Supported versions\n- 0.0.x - Support for Java 9\n- master (1.0.x) - Support for Java 8\n### Advantages\nYou can switch between your scenes from \u003cb\u003eanywhere\u003c/b\u003e through a simple method, without worrying about annoying Stage settings.\n\n## Usage\n### 1. Bind\nAdd FXRouter as project dependency and import it from its package:\n```java\n  import com.github.fxrouter.FXRouter;\n```\nConnect FXRouter to your application stage: call `bind()` from your main class `start()` method (if you use IntelliJ IDEA) or similar:\n```java\nFXRouter.bind(this, primaryStage);\n```\n  ##### You can optionally set application title and size (width, height):\n```java\nFXRouter.bind(this, primaryStage, \"MyApplication\", 800, 600);\n```\n### 2. Set routes\nDefine your Application routes with a \u003cb\u003elabel identifier\u003c/b\u003e and its corresponding \u003cb\u003e.fxml\u003c/b\u003e screen file:\n```java\nFXRouter.when(\"login\", \"myloginscreen.fxml\");\nFXRouter.when(\"profile\", \"myprofilescreen.fxml\");\n// ... others\n```\n##### You can optionally specify the route title and size (width, height):\n```java\nFXRouter.when(\"login\", \"myloginscreen.fxml\", \"My login screen\", 1000, 500);\n```\n### 3. Switch\nSwitch routes from anywhere (controllers, services, etc):\n```java\nFXRouter.goTo(\"login\");     // switch to myloginscreen.fxml\n```\n\n\n### Passing and retrieving data between routes\nYour application could need to pass some data to another route and then retrieve those data:\n#### Send data from the current scene\n`goTo()` accepts two parameters: a \u003cb\u003eroute identifier\u003c/b\u003e and a \u003cb\u003e`Object`\u003c/b\u003e:\n##### (Multiples data could be stored on an appropriate Collection)\n```java\nFXRouter.goTo(\"profile\", \"johndoe22\");     // switch to myprofilescreen.fxml passing an username\n```\n#### Get data from the destination scene\n`getData()` returns a \u003cb\u003e`Object`\u003c/b\u003e which can be cast to appropriate data type:\n```java\nString username = (String) FXRouter.getData();     // retrieve johndoe22\n```\n\n## Example\n#### Without FXRouter\nA common JavaFX project starter:\n```java\npackage sample;\n\nimport javafx.application.Application;\nimport javafx.fxml.FXMLLoader;\nimport javafx.scene.Parent;\nimport javafx.scene.Scene;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage primaryStage) throws Exception{\n        Parent root = FXMLLoader.load(getClass().getResource(\"sample.fxml\"));\n        primaryStage.setTitle(\"Hello World\");\n        primaryStage.setScene(new Scene(root, 300, 275));\n        primaryStage.show();\n    }\n\n\n    public static void main(String[] args) {\n        launch(args);\n    }\n}\n```\n\n#### Using FXRouter \n```java\npackage sample;\n\nimport javafx.application.Application;\nimport javafx.stage.Stage;\nimport sample.FXRouter;                                 // import FXRouter\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage primaryStage) throws Exception{\n    \n        FXRouter.bind(this, primaryStage, \"Hello World\", 300, 275);    // bind FXRouter\n        FXRouter.when(\"firstPage\", \"sample.fxml\");                     // set \"firstPage\" route\n        FXRouter.goTo(\"firstPage\");                                    // switch to \"sample.fxml\"\n    }\n\n\n    public static void main(String[] args) {\n        launch(args);\n    }\n}\n```\n\n### Switch animation\nYou can also set an animation type when you switch between routes:\n```java\nFXRouter.setAnimationType(\"fade\");\n```\n##### You can optionally specify the animation duration (ms):\n```java\nFXRouter.setAnimationType(\"fade\", 1200);\n```\n#### animationType\n| AnimationType  | Default duration |\n| ------------- | ------------- |\n| `fade` | 800  |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcotrombino%2Ffxrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcotrombino%2Ffxrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcotrombino%2Ffxrouter/lists"}