{"id":20496327,"url":"https://github.com/cosinus-code/spring-swing","last_synced_at":"2025-04-13T18:21:05.742Z","repository":{"id":42503007,"uuid":"242805178","full_name":"cosinus-code/spring-swing","owner":"cosinus-code","description":"Spring Swing is a framework designed for building Spring-powered swing applications.","archived":false,"fork":false,"pushed_at":"2025-01-29T14:59:55.000Z","size":684,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T09:04:11.814Z","etag":null,"topics":["spring","spring-boot","swing","swing-gui"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cosinus-code.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":"2020-02-24T17:59:43.000Z","updated_at":"2025-03-02T15:47:23.000Z","dependencies_parsed_at":"2023-01-28T23:46:06.308Z","dependency_job_id":"5d06b834-767d-4767-b5f3-d4c40669e606","html_url":"https://github.com/cosinus-code/spring-swing","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosinus-code%2Fspring-swing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosinus-code%2Fspring-swing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosinus-code%2Fspring-swing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosinus-code%2Fspring-swing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosinus-code","download_url":"https://codeload.github.com/cosinus-code/spring-swing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758961,"owners_count":21157063,"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":["spring","spring-boot","swing","swing-gui"],"created_at":"2024-11-15T18:06:33.904Z","updated_at":"2025-04-13T18:21:05.715Z","avatar_url":"https://github.com/cosinus-code.png","language":"Java","readme":"# Spring Swing\nSpring Swing is a framework designed for building Spring-powered Swing applications.\n\n# Description\n\nIt allows you to start a Swing application in full Spring context. \nIt also allows injection of Spring beans into Swing objects created during application run:\n\n```java\nimport org.cosinus.swing.store.ApplicationStorage;\n\nimport static org.cosinus.swing.context.ApplicationContextInjector.injectContext;\n\npublic class SwingObject {\n\n    @Autowired\n    public ApplicationStorage applicationStorage;\n\n\tpublic SwingApplicationContextAware() {\n        injectContext(this);\n\t}\n}\n```\n\nThere are already Swing object rewritten to auto-inject the Spring context:\n\n```java\nimport org.cosinus.swing.form.Panel;\nimport org.cosinus.swing.store.ApplicationStorage;\n\npublic class MyPanel implements Panel {\n\n    @Autowired\n    public ApplicationStorage applicationStorage;\n\n}\n```\n# Getting Started Using Spring Swing\n\nHere is the Java code for starting a Spring Swing application:\n\n```java\npackage org.cosinus.swing.example;\n\nimport org.cosinus.swing.boot.ApplicationFrame;\nimport org.cosinus.swing.boot.SpringSwingApplication;\nimport org.cosinus.swing.boot.SpringSwingBootApplication;\n\nimport javax.swing.*;\nimport java.awt.*;\n\n@SpringSwingBootApplication\npublic class HelloWorld extends ApplicationFrame {\n\n    @Override\n    public void initComponents() {\n        JPanel panel = new JPanel(new BorderLayout());\n        panel.add(new JLabel(\"Hello World\", SwingConstants.CENTER));\n        add(panel);\n    }\n\n    public static void main(String[] args) {\n        SpringSwingApplication.run(HelloWorld.class, args);\n    }\n}\n```\n\n## Dependencies\n```xml\n  \u003cparent\u003e\n    \u003cgroupId\u003eorg.cosinuscode.swing\u003c/groupId\u003e\n    \u003cartifactId\u003espring-swing-boot-starter-parent\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n  \u003c/parent\u003e\n\n  \u003cdependencies\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.cosinuscode.swing\u003c/groupId\u003e\n      \u003cartifactId\u003espring-swing-boot-starter\u003c/artifactId\u003e\n    \u003c/dependency\u003e\n  \u003c/dependencies\u003e\n```\nSpring Swing runs with java 11, so the compiler should be configured for java 11.\n\n## Package the Application\nThe spring-boot maven plugin can be used for packaging:  \n\n```xml\n  \u003cproperties\u003e\n    ...\n    \u003cproject.output\u003e${project.basedir}/output\u003c/project.output\u003e\n    \u003capplication.name\u003espring-swing-example\u003c/application.name\u003e\n    ...\n  \u003c/properties\u003e\n\n  \u003cbuild\u003e\n    \u003cplugins\u003e\n      ...\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n        \u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e${spring-boot.version}\u003c/version\u003e\n        \u003cexecutions\u003e\n          \u003cexecution\u003e\n            \u003cid\u003erepackage\u003c/id\u003e\n            \u003cconfiguration\u003e\n              \u003cexecutable\u003etrue\u003c/executable\u003e\n              \u003coutputDirectory\u003e${project.output}\u003c/outputDirectory\u003e\n              \u003cfinalName\u003e${application.name}\u003c/finalName\u003e\n            \u003c/configuration\u003e\n          \u003c/execution\u003e\n        \u003c/executions\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n  \u003c/build\u003e\n```\n\nPackage command:\n\n```shell_session\n$ mvn package\n```\n\n## Run the Application\nThe jar can be executed from the `${project.output}` folder:\n\n```shell_session\n$ ./spring-swing-example.jar\n```\n\n## Application Name and Icon\nThe application name (which is the main window title) and the application icon \ncan be specified in the application properties file `application.yml`:\n\n```yaml\nswing:\n  application:\n    name: Sping Swing Example\n    icon: spring.png\n```\nThe icon file default location is in the `image` resources folder.\n \n## Logging\nTo add Apache Log4j 2 to the application exclude the `spring-boot-starter-logging` and add `spring-boot-starter-log4j2`:\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.cosinuscode.swing\u003c/groupId\u003e\n      \u003cartifactId\u003espring-swing-boot-starter\u003c/artifactId\u003e\n      \u003cexclusions\u003e\n        \u003cexclusion\u003e\n          \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n          \u003cartifactId\u003espring-boot-starter-logging\u003c/artifactId\u003e\n        \u003c/exclusion\u003e\n      \u003c/exclusions\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n      \u003cartifactId\u003espring-boot-starter-log4j2\u003c/artifactId\u003e\n    \u003c/dependency\u003e\n```\nThen add log4j2 file to configure the logging. \n\n## Internationalization\nTo translate the message, replace `\"Hello World\"` with `translate(\"hello.world\")` \nand add in the `i18n` resources folder the standard translations properties file \n`messages_en_us.properties`:\n\n```properties\nhello.world=Hello World\n```\n\nTo change the language of the application, add the `preferences.json` file in the `conf` folder \nand specify the preferred language:\n\n```json\n{\n  \"appearance\": {\n    \"language\": {\n      \"type\": \"language\",\n      \"value\": \"fr\"\n    }\n  }\n}\n``` \nalong with the translations file `messages_fr_fr.properties`:\n```properties\nhello.world=Salut monde\n```\n\n## Application Menu\nTo attach a menu to the application, add in the `conf` folder a `menu.json` file with the menu structure \nlike the following:\n```json\n{\n    \"menu\": {\n        \"start.application\": \"control S\",\n        \"quit.application\": \"control Q\"\n    },\n    \"help\": {\n        \"about.application\": \"F1\"\n    }\n}\n```\nTo translate the specific keys (e.g. \"start.application\", \"quit.application\", \"about.application\"), \nadd those in the translation files:\n\n```properties\nhello.world=Hello World\nstart.application=Start\nquit.application=Quit\nabout.application=About\n```\n\n## Add Splash Screen\nTo add a slash screen to the application, just provide the image in `image` resources folder and \nadd it in `SplashScreen-Image` entry of jar manifest using the `maven-jar-plugin`:\n\n```xml\n  \u003cproperties\u003e\n    ...\n    \u003csplash.file.name\u003espring-splash.png\u003c/splash.file.name\u003e\n  \u003c/properties\u003e\n\n  \u003cbuild\u003e\n    \u003cplugins\u003e\n      ...\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n        \u003cartifactId\u003emaven-jar-plugin\u003c/artifactId\u003e\n        \u003cconfiguration\u003e\n          \u003carchive\u003e\n            \u003cmanifestEntries\u003e\n              \u003cSplashScreen-Image\u003eBOOT-INF/classes/image/${splash.file.name}\u003c/SplashScreen-Image\u003e\n            \u003c/manifestEntries\u003e\n          \u003c/archive\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n  \u003c/build\u003e\n```\n\n## Add Startup Progress Bar\nTo add progress bar to the splash screen, \nwe need to pass the `-splash-progress` argument when running the application:\n\n```shell_session\n$ ./spring-swing-example.jar -splash-progress\n```\nThe progress bar can be customized using dedicated arguments:\n```shell_session\n$ ./spring-swing-example.jar \\ \n-splash-progress \\ \n-splash-progress-color=56,123,44 \\ \n-splash-progress-y=245 \\ \n-splash-progress-x=5\n```\n\n## Distribute the Application \nTo simplify the run of the application, \nwe can add the `spring-swing-example.sh` bash file with start command:\n```bash\n#! /bin/bash\nSOURCE=\"${BASH_SOURCE[0]}\"\nwhile [ -h \"$SOURCE\" ]; do\n  APPLICATION_DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" \u003e/dev/null 2\u003e\u00261 \u0026\u0026 pwd )\"\ndone\nAPPLICATION_DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" \u003e/dev/null 2\u003e\u00261 \u0026\u0026 pwd )\"\n\n\"$JAVA_HOME/bin/java\" \\\n-jar $APPLICATION_DIR/spring-swing-example.jar \\\n-splash-progress \\\n-splash-progress-color=56,123,44 \\\n-splash-progress-y=245 \\\n-splash-progress-x=5\n```\nand use `maven-resources-plugin` to copy all resources to the output folder:\n```xml\n  \u003cbuild\u003e\n    \u003cplugins\u003e\n      ...\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n        \u003cartifactId\u003emaven-resources-plugin\u003c/artifactId\u003e\n        \u003cexecutions\u003e\n          \u003cexecution\u003e\n            \u003cid\u003ecopy-run-resources\u003c/id\u003e\n            \u003cphase\u003epackage\u003c/phase\u003e\n            \u003cgoals\u003e\n              \u003cgoal\u003ecopy-resources\u003c/goal\u003e\n            \u003c/goals\u003e\n            \u003cconfiguration\u003e\n              \u003coutputDirectory\u003e${project.output}\u003c/outputDirectory\u003e\n              \u003cresources\u003e\n                \u003cresource\u003e\n                  \u003cdirectory\u003esrc/main/resources\u003c/directory\u003e\n                \u003c/resource\u003e\n              \u003c/resources\u003e\n            \u003c/configuration\u003e\n          \u003c/execution\u003e\n        \u003c/executions\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n  \u003c/build\u003e\n```\nNow simply start the application by running the bash file from the output folder:\n```shell_session\n$ ./spring-swing-example.sh\n```\nThe application properties, preferences, translations and menu structure \ncan now be updated directly from the output folder.\n\n## Examples\nhttps://github.com/cosinus-code/spring-swing-example\n\n# License\nThe Spring Swing is Open Source software released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosinus-code%2Fspring-swing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosinus-code%2Fspring-swing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosinus-code%2Fspring-swing/lists"}