Swing Examples – Formatted TextFields ”; Previous Next Learn how to play with Formatted TextFields in Swing UI programming. Here are most commonly used examples − How to create a masked Text field in Swing? How to use JFormattedTextField in Swing? How to use Percentage format in a Text Box in Swing? How to use Currency format in a Text Box in Swing? How to use Date Format in a Text Box in Swing? Print Page Previous Next Advertisements ”;
Category: swingexamples
Example – Dialogs
Swing Examples – Dialogs ”; Previous Next Learn how to play with Dialogs in Swing UI programming. Here are most commonly used examples − How to show a simple message alert with Ok button in Swing? How to show a warning message dialog in Swing? How to show an error message dialog in Swing? How to show an message dialog with no icon in Swing? How to show an message dialog with custom icon in Swing? How to show a confirm dialog with Yes, No and Cancel option in Swing? How to show a confirm dialog with Yes, No option in Swing? How to show a confirm dialog with Custom texts on Buttons in Swing? How to get user”s input from a list in a input dialog in Swing? How to get user”s input from a text box in a input dialog in Swing? How to create a modal dialog in Swing? How to create a non-modal dialog in Swing? Print Page Previous Next Advertisements ”;
Example – File Choosers
Swing Examples – File Choosers ”; Previous Next Learn how to play with File Choosers in Swing UI programming. Here are most commonly used examples − How to show a open file dialog in Swing? How to show a open file dialog to select multiple files in Swing? How to show a file chooser to select only images in Swing? How to show a file chooser to select directory only in Swing? How to show a file chooser to select both file and directory in Swing? How to show a save file dialog in Swing? Print Page Previous Next Advertisements ”;
Example – Progress Bars
Swing Examples – Progress Bars ”; Previous Next Learn how to play with Progress Bars in Swing UI programming. Here are most commonly used examples − How to show a standard progress bar in Swing? How to show a indeterministic progress bar in Swing? How to use ProgressMonitor in Swing? Print Page Previous Next Advertisements ”;
Example – Environment Setup
Java Swing – Environment Setup ”; Previous Next This section guides you on how to download and set up Java on your machine. Please use the following steps to set up the environment. Java SE is freely available from the link Download Java. Hence, you can download a version based on your operating system. Follow the instructions to download Java and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set the environment variables to point to the correct installation directories. Setting Up the Path for Windows 2000/XP Assuming you have installed Java in c:Program Filesjavajdk directory − Step 1 − Right-click on ”My Computer” and select ”Properties”. Step 2 − Click the ”Environment variables” button under the ”Advanced” tab. Step 3 − Alter the ”Path” variable so that it also contains the path to the Java executable. Example, if the path is currently set to ”C:WINDOWSSYSTEM32”, then change your path to read ”C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin”. Setting Up the Path for Windows 95/98/ME Assuming you have installed Java in c:Program Filesjavajdk directory − Step 1 − Edit the ”C:autoexec.bat” file and add the following line at the end: ”SET PATH=%PATH%;C:Program Filesjavajdkbin”. Setting Up the Path for Linux, UNIX, Solaris, FreeBSD Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your Shell documentation if you have trouble doing this. Example, if you use bash as your shell, then you would add the following line to the end ”.bashrc: export PATH=/path/to/java:$PATH”. Popular Java Editors To write your Java programs, you will need a text editor. There are even more sophisticated IDE available in the market. But for now, you can consider one of the following − Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. Netbeans − Netbeans is a Java IDE that is open source and free, which can be downloaded from https://www.netbeans.org/index.html. Eclipse − Eclipse is also a Java IDE developed by the Eclipse open source community and can be downloaded from https://www.eclipse.org/. Print Page Previous Next Advertisements ”;
Example – CheckBoxes
Swing Examples – CheckBoxes ”; Previous Next Learn how to play with CheckBoxes in Swing UI programming. Here are most commonly used examples − How to create and use Check box in a Java Swing application? How to create and use Radio buttons in a Java Swing application? How to make a radio button group in a Java Swing application? Print Page Previous Next Advertisements ”;
Example – Buttons
Swing Examples – Buttons ”; Previous Next Learn how to play with Buttons in Swing UI programming. Here are most commonly used examples − How to create and use Button in a Java Swing application? How to create a HTML button in Swing? How to create a button with icon and text in Swing? How to modify the default appearance of button in Swing? How to create a toggle button in Swing? How to add a separator in Toolbar buttons. Print Page Previous Next Advertisements ”;
Swing – Quick Guide
SWING – Quick Guide ”; Previous Next SWING – Overview Swing API is a set of extensible GUI Components to ease the developer”s life to create JAVA based Front End/GUI Applications. It is build on top of AWT API and acts as a replacement of AWT API, since it has almost every control corresponding to AWT controls. Swing component follows a Model-View-Controller architecture to fulfill the following criterias. A single API is to be sufficient to support multiple look and feel. API is to be model driven so that the highest level API is not required to have data. API is to use the Java Bean model so that Builder Tools and IDE can provide better services to the developers for use. MVC Architecture Swing API architecture follows loosely based MVC architecture in the following manner. Model represents component”s data. View represents visual representation of the component”s data. Controller takes the input from the user on the view and reflects the changes in Component”s data. Swing component has Model as a seperate element, while the View and Controller part are clubbed in the User Interface elements. Because of which, Swing has a pluggable look-and-feel architecture. Swing Features Light Weight − Swing components are independent of native Operating System”s API as Swing API controls are rendered mostly using pure JAVA code instead of underlying operating system calls. Rich Controls − Swing provides a rich set of advanced controls like Tree, TabbedPane, slider, colorpicker, and table controls. Highly Customizable − Swing controls can be customized in a very easy way as visual apperance is independent of internal representation. Pluggable look-and-feel − SWING based GUI Application look and feel can be changed at run-time, based on available values. SWING – Environment Setup This section guides you on how to download and set up Java on your machine. Please use the following steps to set up the environment. Java SE is freely available from the link Download Java. Hence, you can download a version based on your operating system. Follow the instructions to download Java and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set the environment variables to point to the correct installation directories. Setting Up the Path for Windows 2000/XP Assuming you have installed Java in c:Program Filesjavajdk directory − Step 1 − Right-click on ”My Computer” and select ”Properties”. Step 2 − Click the ”Environment variables” button under the ”Advanced” tab. Step 3 − Alter the ”Path” variable so that it also contains the path to the Java executable. Example, if the path is currently set to ”C:WINDOWSSYSTEM32”, then change your path to read ”C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin”. Setting Up the Path for Windows 95/98/ME Assuming you have installed Java in c:Program Filesjavajdk directory − Step 1 − Edit the ”C:autoexec.bat” file and add the following line at the end: ”SET PATH=%PATH%;C:Program Filesjavajdkbin”. Setting Up the Path for Linux, UNIX, Solaris, FreeBSD Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your Shell documentation if you have trouble doing this. Example, if you use bash as your shell, then you would add the following line to the end ”.bashrc: export PATH=/path/to/java:$PATH”. Popular Java Editors To write your Java programs, you will need a text editor. There are even more sophisticated IDE available in the market. But for now, you can consider one of the following − Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. Netbeans − Netbeans is a Java IDE that is open source and free, which can be downloaded from https://www.netbeans.org/index.html. Eclipse − Eclipse is also a Java IDE developed by the Eclipse open source community and can be downloaded from https://www.eclipse.org/. SWING – Controls Every user interface considers the following three main aspects − UI Elements − These are the core visual elements the user eventually sees and interacts with. GWT provides a huge list of widely used and common elements varying from basic to complex, which we will cover in this tutorial. Layouts − They define how UI elements should be organized on the screen and provide a final look and feel to the GUI (Graphical User Interface). This part will be covered in the Layout chapter. Behavior − These are the events which occur when the user interacts with UI elements. This part will be covered in the Event Handling chapter. Every SWING controls inherits properties from the following Component class hiearchy. S.No. Class & Description 1 Component A Component is the abstract base class for the non menu user-interface controls of SWING. Component represents an object with graphical representation 2 Container A Container is a component that can contain other SWING components 3 JComponent A JComponent is a base class for all SWING UI components. In order to use a SWING component that inherits from JComponent, the component must be in a containment hierarchy whose root is a top-level SWING container SWING UI Elements Following is the list of commonly used controls while designing GUI using SWING. S.No. Class & Description 1 JLabel A JLabel object is a component for placing text in a container. 2 JButton This class creates a labeled button. 3 JColorChooser A JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color. 4 JCheck Box A JCheckBox is a graphical component that can be in either an on (true) or off (false) state. 5 JRadioButton The JRadioButton class is a graphical component that can be in either an on (true) or off (false) state. in a group. 6 JList A JList component presents the user with a scrolling list of text items. 7 JComboBox A JComboBox component presents the user with a to show up menu of choices. 8 JTextField A JTextField object is a text component that allows for the editing of a single line of text. 9
Example – Lists
Swing Examples – Lists ”; Previous Next Learn how to play with Lists in Swing UI programming. Here are most commonly used examples − How to use List boxes in a Java Swing application? How to create a single-interval list box in swing? How to create a multiple-interval-select list box in swing? How to add a separator in a list box in swing? Print Page Previous Next Advertisements ”;
Example – Menus
Swing Examples – Menus ”; Previous Next Learn how to play with Menus in Swing UI programming. Here are most commonly used examples − How to create a menu bar and menu item in swing? How to add a shortcut key to a menu item in swing? How to create a popup menu item in swing? How to add a separator in menu in swing? Print Page Previous Next Advertisements ”;