Swing ..........

Source: Internet
Author: User

1-1: Common swing package

Pachage | content

----------------- | -------------------------------

Javax. Swing | the most common pachage, including the classes of various swing Components

Javax. Swing. Border | Contains classes related to the swing component outer box

Javax .. swing. colorchooser | class designed for the swing color palette component (jcolorchooser)

Javax. Swing. Event | process events generated by the swing component, unlike AWT events

Javax. Swing. filechooser | class designed for the swing file selection dialog box (jfilechooser)

----------------------------------------------

Javax. Swing. plaf | class related to the appearance of swing Components

Javax. Swing. plaf. Basic |

Javax. Swing. plaf. Metal |

Javax. Swing. plaf. multi |

----------------------------------------------

Javax. Swing. Table | class designed for the Swing table component (jtable)

----------------------------------------------

Javax. Swing. Text | Contains classes related to the swing Text Component

Javax.swing.text.html |

Javax.swing.text.html. parser |

Javax. Swing. Text. rtf |

----------------------------------------------

Javax. Swing. Tree | class designed for the swing tree component (jtree)

Javax. Swing. Undo | provides the swing Text Component Redo or undo functions.

1-2: Swing Layout

Almost all components in swing are derived from jcomponent. That is to say, all these components are lightweight component, all written by pure Java code.

In swing, the following components are not inherited by jcomponent:

Jframe (jroot pane)

Jdialog (jroot pane)

Jwindow (jroot pane)

Japplet (jroot pane)

The above four components are heavyweight component. You must use native code to draw these four window components, because to display the window image in the operating system

The window resources of the operating system must be used. In the past, most AWT components were constructed using native code. Therefore, jframe in swing inherits the frame in the original AWT.

Class. The plane does not inherit the jcomponent class. Similarly, japplet inherits the japplet class in the original AWT, and does not inherit the jcomponent class.

Jframe, jdialog, jwindow, and japplet are collectively referred to as the top components, because the rest of the swing components must be attached to one of the four components

Displayed. All four components are implemented (implement) rootpanecontainer interface, which defines containers that are not actually obtained and set by glass pane.

And layered pane (layered pane has content pane and menu bar, while menu bar can be used or not used ),

We cannot add any components to jrootpane because it is just a virtual container. To add components to the top-level components, you must add them to layered pane or

Content pane in Layered pane. Take jframe as an example. Generally, to add other components (such as jbutton and jlabel) to jframe, you must first obtain jframe.

Content pane, and then the component to be added is placed in the content pane, rather than directly added to the jframe. Therefore, to add a button to the jframe, do not

It can be written as frame. Add (button) as before in AWT. Instead, you must first get the content pane of jframe and then add the button to the content pane, for example:

Frame. getcontentpane (). Add (button)

Otherwise, an error message is generated during compilation.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&

Note:

1. the component must be added to the container, and the container itself has a hierarchical relationship, just like a jewelry box, a large box can be placed in a small box, a small box can also be placed in a smaller box, and jewelry can be placed in

In a box, jewelry represents components, and boxes represent containers. Therefore, if you want to add any components to a jframe, you must

The jframe container is obtained first to place these components. Since jframe, jdialog, jwindow, and japplet are the source of the swing component, we can call them the root component.

Component, that is, the so-called top-level component.

2. rootpanecontainer is an interface with a total of five class implementations (implement). They are jframe, jappleet, jwindow, jdialog,

Jinternalframe, where jinternalframe is a lightweight component, which is not a top-level component, that is, jinternalframe cannot be displayed separately and must be attached to the top

In layer components, we will discuss the components below, while jframe, japplet, jwindow, and jdialog are the top components.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&

Rootpanecontainer defines the following methods:

Method

Container getcontentpane () returns contentpane

Component getglasspane () returns glasspane

Jlayeredpane getlayeredpane () returns layeredpane

Jrootpane getrootpane returns the jrootpane of this component.

Void setcontentpane (container contentpane) sets contentpane

Void setglasspane (Component glasspane) sets glasspane

Void setlayeredpane (jlayeredpane layeredpane) sets layeredpane

The following is a simple example of how to obtain content pane from a jframe:ProgramCode:

Public class simple {

Simple (){

Jframe frame = new jframe ();

Container contentpane = frame. getcontentpane ();

Jbutton button = new jbutton ();

Contentpane. Add (button );

}

}

When frame. getcontentpane () is written, the content pane of this frame is returned, that is, a container component. With the container, we can set the button component.

Put in, then jframe has the button component. Therefore, jframe is like an open space. to upload a message to the open space, you should build a house (container) first, and then

, Furniture, equipment, and so on (components) can be moved into the house. The following hierarchical structure shows that the top-level components contain the jrootpane component, and the jrootpane itself contains the content.

Allows the upper-level components to be loaded into other components.

| Frame ------ jframe (jroot pane)

|

Window | dialog ----- jdialog (jroot pane)

|

|

| ----------- Jwindow (jroot pane)

Applet ----------- japplet (jroot pane)

Figure:

| Grass pane

|

Root pane |

| Content pane

| Layered pane |

| Menu bar

 

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.