{"id":23516530,"url":"https://github.com/spaciouscoder78/absolute-java-swing","last_synced_at":"2026-02-13T04:04:31.981Z","repository":{"id":172205372,"uuid":"648984289","full_name":"SpaciousCoder78/absolute-java-swing","owner":"SpaciousCoder78","description":" Learn Java Swing from the scratch for free","archived":false,"fork":false,"pushed_at":"2023-06-03T13:18:07.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T23:47:55.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpaciousCoder78.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,"zenodo":null}},"created_at":"2023-06-03T12:12:16.000Z","updated_at":"2023-06-03T12:12:16.000Z","dependencies_parsed_at":"2023-12-29T17:00:18.242Z","dependency_job_id":null,"html_url":"https://github.com/SpaciousCoder78/absolute-java-swing","commit_stats":null,"previous_names":["spaciouscoder78/absolute-java-swing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SpaciousCoder78/absolute-java-swing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaciousCoder78%2Fabsolute-java-swing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaciousCoder78%2Fabsolute-java-swing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaciousCoder78%2Fabsolute-java-swing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaciousCoder78%2Fabsolute-java-swing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpaciousCoder78","download_url":"https://codeload.github.com/SpaciousCoder78/absolute-java-swing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaciousCoder78%2Fabsolute-java-swing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262724023,"owners_count":23354161,"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":[],"created_at":"2024-12-25T15:13:33.150Z","updated_at":"2026-02-13T04:04:26.943Z","avatar_url":"https://github.com/SpaciousCoder78.png","language":null,"readme":"# absolute-java-swing\n Learn Java Swing from the scratch for free\n \n# Contents\n- What is Swing?\n- How to Use Swing?\n- Creating a window using Swing\n- Adjusting size of the window\n- Closing the window\n\n## What is Swing?\nSwing is a built-in GUI library that comes with JDK. It's a lightweight and easy to use library. It's also an extension of AWT. Swing supports a lot of features and its the ideal library for building simple and interactive desktop GUI apps. JavaFX is the successor of Swing but it has a learning curve and is mostly used for web applications whereas Swing can be used for small-scale GUI applications .\n\n## How to use Swing?\n\nSince Swing is a built-in library, we can directly import it from our java file without the need of Gradle or Maven. \n\nIt can be imported using ```import javax.swing.*``` \n\nOnce you add that line of code to your java file, you can start using Swing's elements in your Java code.\n\n## Creating a window using Swing\n\nIn Swing, we use a JFrame to store our UI elements. It's the basic window where our UI elements are placed. Without a JFrame, we won't be able to see any Swing elements that we code into our app.\n\nLet's create a JFrame now.\n\n``` JFrame frame = new JFrame(\"newwindow\")```\nAnd that's it, we've created a JFrame but if you try to run this code in a main function in your java code, you'll see nothing. It's because by default, JFrame is set to invisible. You need to make it visible by manually typing ```frame.setVisible(true);```.\n\n## Adjusting the size of the window\n\nNow we've made a JFrame. If you run the code, you'll notice that it looks something like this.\n![image](https://github.com/SpaciousCoder78/absolute-java-swing/assets/88923986/0db40992-a6ef-4674-9564-8e232d8fa5cc)\n\nThis is because we didn't set the size of the window. To set the size of the window, add ```frame.setSize(x,y);``` where x is the width and y is the height of the frame.\n\nI'm setting it to 400x400.\n\n![image](https://github.com/SpaciousCoder78/absolute-java-swing/assets/88923986/775d728a-9362-42c9-9460-776dd8c63ca0)\n\nNow it looks nice and neat.\n\n## Closing the window\n\nIf you close the window, you'll notice that the code still doesn't terminate. It still runs. To avoid this, add ```frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);``` to your code.\n\n## Adding components to the JFrame\n\nSo, we've made a \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaciouscoder78%2Fabsolute-java-swing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspaciouscoder78%2Fabsolute-java-swing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaciouscoder78%2Fabsolute-java-swing/lists"}