Why create a Wikiversity account?
Java Programming/Swing
< Java Programming
About Swing Swing library is an official Java GUI toolkit released by Sun Microsystems. Swing is a lightweight component and does not use the native API's of the OS. The main characteristics of the Swing toolkit:
Swing is no longer the latest GUI toolkit for use with Java, being replaced by JavaFX. However, it will remain included in Java for the forseeable future. For more information, see the JavaFX Frequently Asked Questions​.
Packages​[​edit source]
Java Swing first programs​[​edit source]
A basic test application for Swing is as follows:
import javax.swing.JFrame; public class Test extends JFrame { public Test() { setSize(300, 200); setTitle("Test"); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { Test test = new Test(); test.setVisible(true); } }
The constructor contains three function calls. The first two set the size and title of the window. The third statement is used to terminate the application once the window is closed; by default, the program will keep running even though the main function finishes. This is a change from non-graphical Java applications.
Display​[​edit source]
Project: Introduction to Programming in Java
Previous: Introduction to Programming in Java/Arrays — Java Programming/Swing — Next:
Category​: Introduction To Programming in Java
Search
This page was last edited on 2 August 2020, at 23:11.
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.
Privacy policy
About Wikiversity
Disclaimers
Mobile view
Developers
Statistics
Cookie statement

TalkContributionsCreate accountLog in
ResourceDiscuss
ReadEditEdit sourceView history
Visit the main pageMain PageBrowseRecent changesGuided toursRandomHelpDonatePortalColloquiumNewsProjectsSandboxHelp deskWhat links hereRelated changesSpecial pagesPermanent linkPage informationCite this pageCommonsWikibooksWikidataWikinewsWikipediaWikiquoteWikisourceWikispeciesWikivoyageWiktionaryMeta-WikiOutreachMediaWikiWikimaniaCreate a bookDownload as PDFPrintable versionAdd links