JSeparator provides a general purpose component for implementing divider lines - most commonly used as a divider between menu items that breaks them up into logical groupings. Instead of using JSeparator
directly, you can use the JMenu
or JPopupMenu
addSeparator
method to create and add a separator. JSeparator
s may also be used elsewhere in a GUI wherever a visual divider is useful.
For more information and examples see How to Use Menus, a section in The Java Tutorial.
字段摘要 | |
---|---|
String |
alignmentX
Sets the the vertical alignment. |
String |
alignmentY
Sets the the horizontal alignment. |
String |
autoscrolls
Sets the autoscrolls property. |
String |
background
Sets the background color of this component. |
String |
componentOrientation
Sets the language-sensitive orientation that is to be used to order the elements or text within this component. |
String |
cursor
Sets the cursor image to the specified cursor. |
String |
debugOptions
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. |
String |
doubleBuffered
Sets whether this component should use a buffer to paint. |
String |
enabled
Sets whether or not this component is enabled. |
String |
focusTraversalKeysEnabled
Sets whether focus traversal keys are enabled for this Component. |
String |
focusable
Sets the focusable state of this Component to the specified value. |
String |
font
Sets the font for this component. |
String |
foreground
Sets the foreground color of this component. |
String |
ignoreRepaint
Sets whether or not paint messages received from the operating system should be ignored. |
String |
inheritsPopupMenu
Sets whether or not getComponentPopupMenu should delegate to the parent if this component does not have a JPopupMenu assigned to it. |
String |
location
Moves this component to a new location. |
String |
maximumSize
Sets the maximum size of this component to a constant value. |
String |
minimumSize
Sets the minimum size of this component to a constant value. |
String |
name
|
String |
opaque
If true the component paints every pixel within its bounds. |
String |
orientation
Sets the orientation of the separator. The default value of this property is HORIZONTAL. |
String |
preferredSize
Sets the preferred size of this component to a constant value. |
String |
size
Resizes this component so that it has width width and height height . |
String |
toolTipText
Registers the text to display in a tool tip. |
String |
verifyInputWhenFocusTarget
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. |
String |
visible
Makes the component visible or invisible. |
方法摘要 | |
---|---|
|
create
|
子事物摘要 | |
---|---|
|
ActionMap
ActionMap provides mappings from Object s (called keys or Action names) to Action s. An ActionMap is usually used with an InputMap to locate a particular action when a key is pressed. As with InputMap , an ActionMap can have a parent that is searched for keys not defined in the ActionMap . |
|
Border
|
|
BorderLayout
A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH , SOUTH , EAST , WEST , and CENTER . When adding a component to a container with a border layout, use one of these five constants, for example: |
|
BorderLayoutConstraint
|
|
Box
A lightweight container that uses a BoxLayout object as its layout manager. Box provides several class methods that are useful for containers using BoxLayout -- even non-Box containers. |
|
BoxLayout
A layout manager that allows multiple components to be laid out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized. |
|
CardLayout
A CardLayout object is a layout manager for a container. It treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout object is the visible component when the container is first displayed. |
|
ComponentListeners
Adds the specified component listener to receive component events from this component. |
|
ComponentPopupMenu
An implementation of a popup menu -- a small window that pops up and displays a series of choices. A JPopupMenu is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu can also be used anywhere else you want a menu to appear. For example, when the user right-clicks in a specified area. |
|
ContainerListeners
|
|
DropTarget
The DropTarget is associated with a Component when that Component wishes to accept drops during Drag and Drop operations. |
|
FlowLayout
A flow layout arranges components in a directional flow, much like lines of text in a paragraph. The flow direction is determined by the container's componentOrientation property and may be one of two values: |
|
FocusListeners
|
|
GridBagConstraints
The GridBagConstraints class specifies constraints for components that are laid out using the GridBagLayout class. |
|
GridBagLayout
The GridBagLayout class is a flexible layout manager that aligns components vertically, horizontally or along their baseline without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area. |
|
GridLayout
The GridLayout class is a layout manager that lays out a container's components in a rectangular grid. The container is divided into equal-sized rectangles, and one component is placed in each rectangle. |
|
GroupLayout
GroupLayout is a LayoutManager that hierarchically groups components in order to position them in a Container . GroupLayout is intended for use by builders, but may be hand-coded as well. Grouping is done by instances of the Group class. GroupLayout supports two types of groups. A sequential group positions its child elements sequentially, one after another. A parallel group aligns its child elements in one of four ways. |
|
HierarchyBoundsListeners
|
|
HierarchyListeners
|
|
InputMethodListeners
|
|
InputVerifier
|
|
JButton
An implementation of a "push" button. |
|
JCheckBox
An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user. By convention, any number of check boxes in a group can be selected. See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorialfor examples and information on using check boxes. |
|
JColorChooser
JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color. For information about using color choosers, see How to Use Color Choosers, a section in The Java Tutorial. |
|
JComboBox
A component that combines a button or editable field and a drop-down list. The user can select a value from the drop-down list, which appears at the user's request. If you make the combo box editable, then the combo box includes an editable field into which the user can type a value. |
|
JDesktopPane
A container used to create a multiple-document interface or a virtual desktop. You create JInternalFrame objects and add them to the JDesktopPane . JDesktopPane extends JLayeredPane to manage the potentially overlapping internal frames. It also maintains a reference to an instance of DesktopManager that is set by the UI class for the current look and feel (L&F). Note that JDesktopPane does not support borders. |
|
JEditorPane
A text component to edit various kinds of content. You can find how-to information and examples of using editor panes in Using Text Components, a section in The Java Tutorial. |
|
JFileChooser
JFileChooser provides a simple mechanism for the user to choose a file. For information about using JFileChooser , see How to Use File Choosers, a section in The Java Tutorial. |
|
JFormattedTextField
JFormattedTextField extends JTextField adding support for formatting arbitrary values, as well as retrieving a particular object once the user has edited the text. The following illustrates configuring a JFormattedTextField to edit dates: |
|
JInternalFrame
A lightweight object that provides many of the features of a native frame, including dragging, closing, becoming an icon, resizing, title display, and support for a menu bar. For task-oriented documentation and examples of using internal frames, see How to Use Internal Frames, a section in The Java Tutorial. |
|
JLabel
A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can't display it. |
|
JLayer
JLayer is a universal decorator for Swing components which enables you to implement various advanced painting effects as well as receive notifications of all AWTEvent s generated within its borders. |
|
JLayeredPane
JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed. An Integer object specifies each component's depth in the container, where higher-numbered components sit "on top" of other components. For task-oriented documentation and examples of using layered panes see How to Use a Layered Pane, a section in The Java Tutorial. |
|
JList
A component that displays a list of objects and allows the user to select one or more items. A separate model, ListModel , maintains the contents of the list. |
|
JMenu
An implementation of a menu -- a popup window containing JMenuItem s that is displayed when the user selects an item on the JMenuBar . In addition to JMenuItem s, a JMenu can also contain JSeparator s. |
|
JMenuBar
An implementation of a menu bar. You add JMenu objects to the menu bar to construct a menu. When the user selects a JMenu object, its associated JPopupMenu is displayed, allowing the user to select one of the JMenuItems on it. |
|
JOptionPane
JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. For information about using JOptionPane , see How to Make Dialogs, a section in The Java Tutorial. |
|
JPanel
JPanel is a generic lightweight container. For examples and task-oriented documentation for JPanel, see How to Use Panels, a section in The Java Tutorial. |
|
JPasswordField
JPasswordField is a lightweight component that allows the editing of a single line of text where the view indicates something was typed, but does not show the original characters. You can find further information and examples in How to Use Text Fields, a section in The Java Tutorial. |
|
JPopupMenu
An implementation of a popup menu -- a small window that pops up and displays a series of choices. A JPopupMenu is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu can also be used anywhere else you want a menu to appear. For example, when the user right-clicks in a specified area. |
|
JProgressBar
A component that visually displays the progress of some task. As the task progresses towards completion, the progress bar displays the task's percentage of completion. This percentage is typically represented visually by a rectangle which starts out empty and gradually becomes filled in as the task progresses. In addition, the progress bar can display a textual representation of this percentage. |
|
JRadioButton
An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user. Used with a ButtonGroup object to create a group of buttons in which only one button at a time can be selected. (Create a ButtonGroup object and use its add method to include the JRadioButton objects in the group.) |
|
JScrollBar
An implementation of a scrollbar. The user positions the knob in the scrollbar to determine the contents of the viewing area. The program typically adjusts the display so that the end of the scrollbar represents the end of the displayable contents, or 100% of the contents. The start of the scrollbar is the beginning of the displayable contents, or 0%. The position of the knob within those bounds then translates to the corresponding percentage of the displayable contents. |
|
JScrollPane
Provides a scrollable view of a lightweight component. A JScrollPane manages a viewport, optional vertical and horizontal scroll bars, and optional row and column heading viewports. You can find task-oriented documentation of JScrollPane in How to Use Scroll Panes, a section in The Java Tutorial. Note that JScrollPane does not support heavyweight components. |
|
JSeparator
JSeparator provides a general purpose component for implementing divider lines - most commonly used as a divider between menu items that breaks them up into logical groupings. Instead of using JSeparator directly, you can use the JMenu or JPopupMenu addSeparator method to create and add a separator. JSeparator s may also be used elsewhere in a GUI wherever a visual divider is useful. |
|
JSlider
A component that lets the user graphically select a value by sliding a knob within a bounded interval. The knob is always positioned at the points that match integer values within the specified interval. |
|
JSpinner
A single line input field that lets the user select a number or an object value from an ordered sequence. Spinners typically provide a pair of tiny arrow buttons for stepping through the elements of the sequence. The keyboard up/down arrow keys also cycle through the elements. The user may also be allowed to type a (legal) value directly into the spinner. Although combo boxes provide similar functionality, spinners are sometimes preferred because they don't require a drop down list that can obscure important data. |
|
JSplitPane
JSplitPane is used to divide two (and only two) Component s. The two Component s are graphically divided based on the look and feel implementation, and the two Component s can then be interactively resized by the user. Information on using JSplitPane is in How to Use Split Panes in The Java Tutorial. |
|
JTabbedPane
A component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon. For examples and information on using tabbed panes see How to Use Tabbed Panes, a section in The Java Tutorial. |
|
JTable
The JTable is used to display and edit regular two-dimensional tables of cells. See How to Use Tables in The Java Tutorial for task-oriented documentation and examples of using JTable . |
|
JTextArea
A JTextArea is a multi-line area that displays plain text. It is intended to be a lightweight component that provides source compatibility with the java.awt.TextArea class where it can reasonably do so. You can find information and examples of using all the text components in Using Text Components, a section in The Java Tutorial. |
|
JTextField
JTextField is a lightweight component that allows the editing of a single line of text. For information on and examples of using text fields, see How to Use Text Fields in The Java Tutorial. |
|
JToggleButton
An implementation of a two-state button. The JRadioButton and JCheckBox classes are subclasses of this class. For information on using them see How to Use Buttons, Check Boxes, and Radio Buttons, a section in The Java Tutorial. |
|
JToolBar
JToolBar provides a component that is useful for displaying commonly used Action s or controls. For examples and information on using tool bars see How to Use Tool Bars, a section in The Java Tutorial. |
|
JTree
A control that displays a set of hierarchical data as an outline. You can find task-oriented documentation and examples of using trees in How to Use Trees, a section in The Java Tutorial. |
|
JViewport
The "viewport" or "porthole" through which you see the underlying information. When you scroll, what moves is the viewport. It is like peering through a camera's viewfinder. Moving the viewfinder upwards brings new things into view at the top of the picture and loses things that were at the bottom. |
|
KeyListeners
|
|
MouseListeners
|
|
MouseMotionListeners
|
|
MouseWheelListeners
|
|
OverlayLayout
A layout manager to arrange components over the top of each other. The requested size of the container will be the largest requested size of the children, taking alignment needs into consideration. The alignment is based upon what is needed to properly fit the children in the allocation area. The children will be placed such that their alignment points are all on top of each other. |
|
PropertyChangeListeners
|
|
TransferHandler
|
字段详细信息 |
---|
Sets the the vertical alignment.
Sets the the horizontal alignment.
Sets the autoscrolls
property.
Sets the background color of this component.
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
Sets the cursor image to the specified cursor.
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
Sets whether this component should use a buffer to paint.
Sets whether or not this component is enabled.
Sets whether focus traversal keys are enabled for this Component.
Sets the focusable state of this Component to the specified value.
Sets the font for this component.
Sets the foreground color of this component.
Sets whether or not paint messages received from the operating system should be ignored.
Sets whether or not getComponentPopupMenu
should delegate to the parent if this component does not have a JPopupMenu
assigned to it.
Moves this component to a new location.
Sets the maximum size of this component to a constant value.
Sets the minimum size of this component to a constant value.
If true the component paints every pixel within its bounds.
Sets the orientation of the separator. The default value of this property is HORIZONTAL.
Sets the preferred size of this component to a constant value.
Resizes this component so that it has width width
and height height
.
Registers the text to display in a tool tip.
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus.
Makes the component visible or invisible.
方法详细信息 |
---|
子事物详细信息 |
---|
ActionMap provides mappings from Object
s (called keys or Action
names) to Action
s. An ActionMap
is usually used with an InputMap
to locate a particular action when a key is pressed. As with InputMap
, an ActionMap
can have a parent that is searched for keys not defined in the ActionMap
.
A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH
, SOUTH
, EAST
, WEST
, and CENTER
. When adding a component to a container with a border layout, use one of these five constants, for example:
Panel p = new Panel(); p.setLayout(new BorderLayout()); p.add(new Button("Okay"), BorderLayout.SOUTH);
A lightweight container that uses a BoxLayout object as its layout manager. Box provides several class methods that are useful for containers using BoxLayout -- even non-Box containers.
The Box
class can create several kinds of invisible components that affect layout: glue, struts, and rigid areas. If all the components your Box
contains have a fixed size, you might want to use a glue component (returned by createGlue
) to control the components' positions. If you need a fixed amount of space between two components, try using a strut (createHorizontalStrut
or createVerticalStrut
). If you need an invisible component that always takes up the same amount of space, get it by invoking createRigidArea
.
If you are implementing a BoxLayout
you can find further information and examples in How to Use BoxLayout, a section in The Java Tutorial.
A layout manager that allows multiple components to be laid out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized.
A CardLayout
object is a layout manager for a container. It treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout
object is the visible component when the container is first displayed.
Adds the specified component listener to receive component events from this component.
An implementation of a popup menu -- a small window that pops up and displays a series of choices. A JPopupMenu
is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu
can also be used anywhere else you want a menu to appear. For example, when the user right-clicks in a specified area.
For information and examples of using popup menus, see How to Use Menus in The Java Tutorial.
The DropTarget
is associated with a Component
when that Component
wishes to accept drops during Drag and Drop operations.
Each DropTarget
is associated with a FlavorMap
. The default FlavorMap
hereafter designates the FlavorMap
returned by SystemFlavorMap.getDefaultFlavorMap()
.
A flow layout arranges components in a directional flow, much like lines of text in a paragraph. The flow direction is determined by the container's componentOrientation
property and may be one of two values:
ComponentOrientation.LEFT_TO_RIGHT
ComponentOrientation.RIGHT_TO_LEFT
Flow layouts are typically used to arrange buttons in a panel. It arranges buttons horizontally until no more buttons fit on the same line. The line alignment is determined by the align
property. The possible values are:
The GridBagConstraints
class specifies constraints for components that are laid out using the GridBagLayout
class.
The GridBagLayout
class is a flexible layout manager that aligns components vertically, horizontally or along their baseline without requiring that the components be of the same size. Each GridBagLayout
object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area.
The GridLayout
class is a layout manager that lays out a container's components in a rectangular grid. The container is divided into equal-sized rectangles, and one component is placed in each rectangle.
GroupLayout is a LayoutManager
that hierarchically groups components in order to position them in a Container
. GroupLayout
is intended for use by builders, but may be hand-coded as well. Grouping is done by instances of the Group
class. GroupLayout
supports two types of groups. A sequential group positions its child elements sequentially, one after another. A parallel group aligns its child elements in one of four ways.
GroupLayout必须放到容器的最后一个,因为会用到容器的组件。
An implementation of a "push" button.
Buttons can be configured, and to some degree controlled, by Action
s. Using an Action
with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action
for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.
See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorial for information and examples of using buttons.
An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user. By convention, any number of check boxes in a group can be selected. See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorialfor examples and information on using check boxes.
Buttons can be configured, and to some degree controlled, by Action
s. Using an Action
with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action
for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.
JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color. For information about using color choosers, see How to Use Color Choosers, a section in The Java Tutorial.
This class provides three levels of API:
ActionListeners
can be specified to be invoked when the user presses one of the dialog buttons.JColorChooser
panes directly (within any container). PropertyChange
listeners can be added to detect when the current "color" property changes.A component that combines a button or editable field and a drop-down list. The user can select a value from the drop-down list, which appears at the user's request. If you make the combo box editable, then the combo box includes an editable field into which the user can type a value.
A container used to create a multiple-document interface or a virtual desktop. You create JInternalFrame
objects and add them to the JDesktopPane
. JDesktopPane
extends JLayeredPane
to manage the potentially overlapping internal frames. It also maintains a reference to an instance of DesktopManager
that is set by the UI class for the current look and feel (L&F). Note that JDesktopPane
does not support borders.
A text component to edit various kinds of content. You can find how-to information and examples of using editor panes in Using Text Components, a section in The Java Tutorial.
JFileChooser provides a simple mechanism for the user to choose a file. For information about using JFileChooser
, see How to Use File Choosers, a section in The Java Tutorial.
The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:
JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(parent); if(returnVal == JFileChooser.APPROVE_OPTION) { System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName()); }
JFormattedTextField extends JTextField
adding support for formatting arbitrary values, as well as retrieving a particular object once the user has edited the text. The following illustrates configuring a JFormattedTextField
to edit dates:
JFormattedTextField ftf = new JFormattedTextField(); ftf.setValue(new Date());
Once a JFormattedTextField
has been created, you can listen for editing changes by way of adding a PropertyChangeListener
and listening for PropertyChangeEvent
s with the property name value
.
A lightweight object that provides many of the features of a native frame, including dragging, closing, becoming an icon, resizing, title display, and support for a menu bar. For task-oriented documentation and examples of using internal frames, see How to Use Internal Frames, a section in The Java Tutorial.
Generally, you add JInternalFrame
s to a JDesktopPane
. The UI delegates the look-and-feel-specific actions to the DesktopManager
object maintained by the JDesktopPane
.
The JInternalFrame
content pane is where you add child components. As a conveniance add
and its variants, remove
and setLayout
have been overridden to forward to the contentPane
as necessary. This means you can write:
internalFrame.add(child);
And the child will be added to the contentPane. The content pane is actually managed by an instance of JRootPane
, which also manages a layout pane, glass pane, and optional menu bar for the internal frame. Please see the JRootPane
documentation for a complete description of these components. Refer to RootPaneContainer
for details on adding, removing and setting the LayoutManager
of a JInternalFrame
.
A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can't display it.
A JLabel
object can display either text, an image, or both. You can specify where in the label's display area the label's contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.
You can also specify the position of the text relative to the image. By default, text is on the trailing edge of the image, with the text and image vertically aligned.
A label's leading and trailing edge are determined from the value of its ComponentOrientation
property. At present, the default ComponentOrientation setting maps the leading edge to left and the trailing edge to right.
Finally, you can use the setIconTextGap
method to specify how many pixels should appear between the text and the image. The default is 4 pixels.
See How to Use Labels in The Java Tutorial for further documentation.
JLayer is a universal decorator for Swing components which enables you to implement various advanced painting effects as well as receive notifications of all AWTEvent
s generated within its borders.
Since:
1.7
JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed. An Integer
object specifies each component's depth in the container, where higher-numbered components sit "on top" of other components. For task-oriented documentation and examples of using layered panes see How to Use a Layered Pane, a section in The Java Tutorial.
A component that displays a list of objects and allows the user to select one or more items. A separate model, ListModel
, maintains the contents of the list.
An implementation of a menu -- a popup window containing JMenuItem
s that is displayed when the user selects an item on the JMenuBar
. In addition to JMenuItem
s, a JMenu
can also contain JSeparator
s.
In essence, a menu is a button with an associated JPopupMenu
. When the "button" is pressed, the JPopupMenu
appears. If the "button" is on the JMenuBar
, the menu is a top-level window. If the "button" is another menu item, then the JPopupMenu
is "pull-right" menu.
Menus can be configured, and to some degree controlled, by Action
s. Using an Action
with a menu has many benefits beyond directly configuring a menu. Refer to Swing Components Supporting Action
for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.
For information and examples of using menus see How to Use Menus, a section in The Java Tutorial.
An implementation of a menu bar. You add JMenu
objects to the menu bar to construct a menu. When the user selects a JMenu
object, its associated JPopupMenu
is displayed, allowing the user to select one of the JMenuItems
on it.
For information and examples of using menu bars see How to Use Menus, a section in The Java Tutorial.
JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. For information about using JOptionPane
, see How to Make Dialogs, a section in The Java Tutorial.
JPanel is a generic lightweight container. For examples and task-oriented documentation for JPanel, see How to Use Panels, a section in The Java Tutorial.
JPasswordField is a lightweight component that allows the editing of a single line of text where the view indicates something was typed, but does not show the original characters. You can find further information and examples in How to Use Text Fields, a section in The Java Tutorial.
JPasswordField
is intended to be source-compatible with java.awt.TextField
used with echoChar
set. It is provided separately to make it easier to safely change the UI for the JTextField
without affecting password entries.
An implementation of a popup menu -- a small window that pops up and displays a series of choices. A JPopupMenu
is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu
can also be used anywhere else you want a menu to appear. For example, when the user right-clicks in a specified area.
For information and examples of using popup menus, see How to Use Menus in The Java Tutorial.
A component that visually displays the progress of some task. As the task progresses towards completion, the progress bar displays the task's percentage of completion. This percentage is typically represented visually by a rectangle which starts out empty and gradually becomes filled in as the task progresses. In addition, the progress bar can display a textual representation of this percentage.
An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user. Used with a ButtonGroup
object to create a group of buttons in which only one button at a time can be selected. (Create a ButtonGroup object and use its add
method to include the JRadioButton objects in the group.)
Note: The ButtonGroup object is a logical grouping -- not a physical grouping. To create a button panel, you should still create aJPanel
or similar container-object and add aBorder
to it to set it off from surrounding components.
Buttons can be configured, and to some degree controlled, by Action
s. Using an Action
with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action
for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.
See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorial for further documentation.
An implementation of a scrollbar. The user positions the knob in the scrollbar to determine the contents of the viewing area. The program typically adjusts the display so that the end of the scrollbar represents the end of the displayable contents, or 100% of the contents. The start of the scrollbar is the beginning of the displayable contents, or 0%. The position of the knob within those bounds then translates to the corresponding percentage of the displayable contents.
Typically, as the position of the knob in the scrollbar changes a corresponding change is made to the position of the JViewport on the underlying view, changing the contents of the JViewport.
Provides a scrollable view of a lightweight component. A JScrollPane
manages a viewport, optional vertical and horizontal scroll bars, and optional row and column heading viewports. You can find task-oriented documentation of JScrollPane
in How to Use Scroll Panes, a section in The Java Tutorial. Note that JScrollPane
does not support heavyweight components.
JSeparator provides a general purpose component for implementing divider lines - most commonly used as a divider between menu items that breaks them up into logical groupings. Instead of using JSeparator
directly, you can use the JMenu
or JPopupMenu
addSeparator
method to create and add a separator. JSeparator
s may also be used elsewhere in a GUI wherever a visual divider is useful.
For more information and examples see How to Use Menus, a section in The Java Tutorial.
A component that lets the user graphically select a value by sliding a knob within a bounded interval. The knob is always positioned at the points that match integer values within the specified interval.
The slider can show both major tick marks, and minor tick marks between the major ones. The number of values between the tick marks is controlled with setMajorTickSpacing
and setMinorTickSpacing
. Painting of tick marks is controlled by setPaintTicks
.
Sliders can also print text labels at regular intervals (or at arbitrary locations) along the slider track. Painting of labels is controlled by setLabelTable
and setPaintLabels
.
For further information and examples see How to Use Sliders, a section in The Java Tutorial.
A single line input field that lets the user select a number or an object value from an ordered sequence. Spinners typically provide a pair of tiny arrow buttons for stepping through the elements of the sequence. The keyboard up/down arrow keys also cycle through the elements. The user may also be allowed to type a (legal) value directly into the spinner. Although combo boxes provide similar functionality, spinners are sometimes preferred because they don't require a drop down list that can obscure important data.
JSplitPane is used to divide two (and only two) Component
s. The two Component
s are graphically divided based on the look and feel implementation, and the two Component
s can then be interactively resized by the user. Information on using JSplitPane
is in How to Use Split Panes in The Java Tutorial.
A component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon. For examples and information on using tabbed panes see How to Use Tabbed Panes, a section in The Java Tutorial.
The JTable
is used to display and edit regular two-dimensional tables of cells. See How to Use Tables in The Java Tutorial for task-oriented documentation and examples of using JTable
.
A JTextArea
is a multi-line area that displays plain text. It is intended to be a lightweight component that provides source compatibility with the java.awt.TextArea
class where it can reasonably do so. You can find information and examples of using all the text components in Using Text Components, a section in The Java Tutorial.
JTextField is a lightweight component that allows the editing of a single line of text. For information on and examples of using text fields, see How to Use Text Fields in The Java Tutorial.
An implementation of a two-state button. The JRadioButton
and JCheckBox
classes are subclasses of this class. For information on using them see How to Use Buttons, Check Boxes, and Radio Buttons, a section in The Java Tutorial.
Buttons can be configured, and to some degree controlled, by Action
s. Using an Action
with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action
for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.
JToolBar provides a component that is useful for displaying commonly used Action
s or controls. For examples and information on using tool bars see How to Use Tool Bars, a section in The Java Tutorial.
With most look and feels, the user can drag out a tool bar into a separate window (unless the floatable
property is set to false
). For drag-out to work correctly, it is recommended that you add JToolBar
instances to one of the four "sides" of a container whose layout manager is a BorderLayout
, and do not add children to any of the other four "sides".
A control that displays a set of hierarchical data as an outline. You can find task-oriented documentation and examples of using trees in How to Use Trees, a section in The Java Tutorial.
The "viewport" or "porthole" through which you see the underlying information. When you scroll, what moves is the viewport. It is like peering through a camera's viewfinder. Moving the viewfinder upwards brings new things into view at the top of the picture and loses things that were at the bottom.
A layout manager to arrange components over the top of each other. The requested size of the container will be the largest requested size of the children, taking alignment needs into consideration. The alignment is based upon what is needed to properly fit the children in the allocation area. The children will be placed such that their alignment points are all on top of each other.