About Java Swing

Source: Internet
Author: User

Java application User Interface development Package
Swing is a development kit for developing the Java application user interface. It is based on the Abstract Window Toolkit (AWT) and enables cross-platform applications to use any pluggable styling. Swing developers can use Swing's rich, flexible features and modular components to create elegant user interfaces with little code.
All packages in the toolkit are named for swing, such as Javax.swing,javax.swing.event
To create a graphical interface step with swing:
(1) Import swing Package
(2) Select the interface style
(3) Setting the top-level container
(4) Setting buttons and labels
(5) Placing the component on the container
(6) Add a border to the component
(7) Handling events
(8) Auxiliary technical support
1. Import Swing Package
The following statement imports the swing package
Import javax.swing.*;
Most swing programs use AWT's underlying infrastructure and event model, so you need to import two packages:
Import java.awt.*;
Import java.awt.event.*;
If event handling is included in the graphical interface, you also need to import the event processing package:
Import javax.swing.event.*;
2. Select the interface style
Swing allows the selection of graphical interface styles for programs commonly used in Java style, Windows style, etc.
The following code is used to choose the GUI style, which is a cross-platform Java interface style.
try {uimanager.setlookandfeel (
Uimanager.getcrossplatformlookandfeelclassname ()); }
catch (Exception e) {}
(3) Setting the top-level container
The graphical interface must have at least one top-level swing container
Top Swing containers provide support for drawing and handling events on the screen for other swing components
Common top-level containers:
JFrame (frame): Represents the main program window
JDialog (dialog box): Each JDialog object represents a dialog box that belongs to a Level two window
JApplet (APPLET): Display a small program interface within the browser
A frame includes a boundary, a menu bar, a toolbar, a status bar, and a pane that occupies the main part of the middle
Panes can also be viewed as a panel, but it is a part of the framework
Components are not placed directly on the frame, but are placed on several panels, which are then placed on a pane
Use the Getcontentpane () function of the frame object to get the pane, and then call the pane's Add () function to place the panel
public static void Main (string[]args) {JFrame frame=new JFrame ("swingapplication");
JPanel panel1=new JPanel ();
Frame.getcontentpane (). Add (Panel1,borderlayout.center);
...//Add other components
Frame.pack (); frame.setvisible (true);}

About Java Swing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.