Base class of all button-like widgets, such as push buttons, check boxes, and radio buttons.
Base class of all button-like widgets, such as push buttons, check boxes, and radio buttons.
javax.swing.AbstractButton
An abstract action to be performed in reaction to user input.
An abstract action to be performed in reaction to user input.
Not every action component will honor every property of its action. An action itself can generally be configured so that certain properties should be ignored and instead taken from the component directly. In the end, it is up to a component which property it uses in which way.
javax.swing.Action
Clients should implement the ui field.
Clients should implement the ui field. See the SimpleApplet
demo for an example.
Note: Applet
extends javax.swing.JApplet
to satisfy Java's applet loading mechanism. The usual component wrapping
scheme doesn't work here.
javax.swing.JApplet
A container that arranges its children around a central component that takes most of the space.
A container that arranges its children around a central component that takes most of the space. The other children are placed on one of four borders: north, east, south, west.
javax.swing.BorderLayout
A panel that lays out its contents one after the other, either horizontally or vertically.
A panel that lays out its contents one after the other, either horizontally or vertically.
javax.swing.BoxLayout
Default partial implementation for buffer adapters.
A button that can be clicked, usually to perform some action.
A button that can be clicked, usually to perform some action.
javax.swing.JButton
A button mutex.
A button mutex. At most one of its associated buttons is selected at a time.
javax.swing.ButtonGroup
Two state button that can either be checked or unchecked.
Two state button that can either be checked or unchecked.
javax.swing.JCheckBox
A menu item with a check box.
A menu item with a check box.
javax.swing.JCheckBoxMenuItem
Let's the user make a selection from a list of predefined items.
Let's the user make a selection from a list of predefined items. Visually, this is implemented as a button-like component with a pull-down menu.
javax.swing.JComboBox
Base class for all UI elements that can be displayed in a window.
Base class for all UI elements that can be displayed in a window. Components are publishers that fire the following event classes: ComponentEvent, FocusEvent, FontChanged, ForegroundChanged, BackgroundChanged.
[Java Swing] Unlike in Java Swing, not all components are also containers.
http://java.sun.com/products/jfc/tsc/articles/painting/ for the component painting mechanism
javax.swing.JComponent
The base traits for UI elements that can contain Component
s.
The base traits for UI elements that can contain Component
s.
[Java Swing] This is not the wrapper for java.awt.Container but a trait that extracts a common interface for components, menus, and windows.
A dialog window.
A dialog window.
javax.swing.JDialog
A text component that allows multi-line text input and display.
A text component that allows multi-line text input and display.
javax.swing.JEditorPane
Used to open file dialogs.
Used to open file dialogs.
A panel that arranges its contents horizontally, one after the other.
A panel that arranges its contents horizontally, one after the other. If they don't fit, this panel will try to insert line breaks.
java.awt.FlowLayout
A text field with formatted input.
A text field with formatted input.
javax.swing.JFormattedTextField
A window with decoration such as a title, border, and action buttons.
A window with decoration such as a title, border, and action buttons.
An AWT window cannot be wrapped dynamically with this class, i.e., you cannot write something like new Window { def peer = myAWTWindow }
javax.swing.JFrame
A panel that arranges its children in a grid.
A panel that arranges its children in a grid. Layout details can be given for each cell of the grid.
java.awt.GridBagLayout
A panel that lays out its contents in a uniform grid.
A panel that lays out its contents in a uniform grid.
java.awt.GridLayout
A label component that display either a text, an icon, or both.
A label component that display either a text, an icon, or both.
javax.swing.JLabel
A container that associates layout constraints of member type
Constraints
with its children.
A container that associates layout constraints of member type
Constraints
with its children.
See GridBagPanel
for an example container with custom constraints.
[Java Swing] In scala.swing, panels and layout managers are combined into subclasses of this base class. This approach allows for typed component constraints.
A component that displays a number of elements in a list.
A component that displays a number of elements in a list. A list view does not support inline editing of items. If you need it, use a table view instead.
Named ListView
to avoid a clash with the frequently used
scala.List
javax.swing.JList
A frame that can be used for main application windows.
A frame that can be used for main application windows. It shuts down the framework and quits the application when closed.
Default partial implementation for mutable map adapters.
A menu.
A menu. Contains menu items. Being a menu item itself, menus can be nested.
javax.swing.JMenu
A menu bar.
A menu bar. Each window can contain at most one. Contains a number of menus.
javax.swing.JMenuBar
A menu item that can be used in a menu.
A menu item that can be used in a menu.
javax.swing.JMenuItem
An Oriented
whose orientation can be changed.
An Oriented
whose orientation can be changed.
Something that can have an orientation.
A component that can contain other components.
A component that can contain other components.
javax.swing.JPanel
A password field, that displays a replacement character for each character in the password.
A password field, that displays a replacement character for each character in the password.
javax.swing.JPasswordField
A popup menu.
A popup menu.
Example usage:
val popupMenu = new PopupMenu { contents += new Menu("menu 1") { contents += new RadioMenuItem("radio 1.1") contents += new RadioMenuItem("radio 1.2") } contents += new Menu("menu 2") { contents += new RadioMenuItem("radio 2.1") contents += new RadioMenuItem("radio 2.2") } } val button = new Button("Show Popup Menu") reactions += { case e: ButtonClicked => popupMenu.show(button, 0, button.bounds.height) } listenTo(button)
javax.swing.JPopupMenu
A bar indicating progress of some action.
A bar indicating progress of some action. Can be in indeterminate mode, in which it indicates that the action is in progress (usually by some animation) but does not indicate the amount of work done or to be done.
javax.swing.JProgressBar
Notifies registered reactions when an event is published.
Notifies registered reactions when an event is published. Publishers are also reactors and listen to themselves per default as a convenience.
In order to reduce memory leaks, reactions are weakly referenced by default,
unless they implement Reactions.StronglyReferenced
. That way,
the lifetime of reactions are more easily bound to the registering object,
which are reactors in common client code and hold strong references to their
reactions. As a result, reactors can be garbage collected even though they
still have reactions registered at some publisher, but not vice versa
since reactors (strongly) reference publishers they are interested in.
A two state button that is usually used in a ButtonGroup
together with other RadioButton
s, in order to indicate
that at most one of them can be selected.
A two state button that is usually used in a ButtonGroup
together with other RadioButton
s, in order to indicate
that at most one of them can be selected.
javax.swing.JRadioButton
A menu item with a radio button.
A menu item with a radio button.
javax.swing.JRadioButtonMenuItem
Used by reactors to let clients register custom event reactions.
The counterpart to publishers.
The counterpart to publishers. Listens to events from registered publishers.
A window that adds some functionality to the plain Window class and serves as the common base class for frames and dialogs.
A window that adds some functionality to the plain Window class and serves as the common base class for frames and dialogs.
Implementation note: this class is sealed since we need to know that a rich window is either a dialog or a frame at some point.
The root of a component hierarchy.
The root of a component hierarchy. Contains at most one component.
javax.swing.RootPaneContainer
Can have at most a single child component, which will be put inside a canvas (the viewport) that can be scrolled.
Can have at most a single child component, which will be put inside a canvas (the viewport) that can be scrolled.
javax.swing.JScrollPane
A component that is specially suitable for being placed inside a
ScrollPane
.
A component that is specially suitable for being placed inside a
ScrollPane
.
javax.swing.Scrollable
A bar that can be used a separator, most commonly in menus.
A bar that can be used a separator, most commonly in menus.
javax.swing.JSeparator
A container for which a sequential order of children makes sense, such as flow panels, or menus.
A container for which a sequential order of children makes sense, such as flow panels, or menus. Its contents are mutable.
Default partial implementation for mutable set adapters.
Extend this class for most simple UI applications.
Extend this class for most simple UI applications. Clients need to
implement the top
method. Framework initialization is done by this class.
In order to conform to Swing's threading policy, never implement top or any
additional member that created Swing components as a value unless component
creation happens on the EDT (see Swing.onEDT
and Swing.onEDTWait
).
Lazy values are okay for the same reason if they are initialized on the EDT
always.
Lets users select a value from a given range.
Lets users select a value from a given range. Visually, this is represented as a draggable knob on a horizontal or vertical bar.
Fires a ValueChanged event whenever the slider's value changes and when the knob is released.
javax.swing.JSlider
A container with exactly two children.
A container with exactly two children. Arranges them side by side, either horizontally or vertically. Displays a draggable divider component between them that lets the user adjust the size ratio of the children.
javax.swing.JSplitPane
Convenience class with utility methods for GUI applications.
Displays the contents of one of several pages at a time.
Displays the contents of one of several pages at a time. For each page a tab is visible at all times. The user can click on one of these tabs to move the corresponding page to the front.
javax.swing.JTabbedPane
Displays a matrix of items.
Displays a matrix of items.
To obtain a scrollable table or row and columns headers, wrap the table in a scroll pane.
javax.swing.JTable
A text component that allows multi-line text input and display.
A text component that allows multi-line text input and display.
javax.swing.JTextArea
A component that allows some kind of text input and display.
A component that allows some kind of text input and display.
javax.swing.JTextComponent
A text component that allows single line text input and display.
A text component that allows single line text input and display.
javax.swing.JTextField
A text component used to model styled paragraphs of text.
A text component used to model styled paragraphs of text.
javax.swing.JTextPane
A two state button with a push button like user interface.
A two state button with a push button like user interface. Usually used in tool bars.
javax.swing.JToggleButton
Like a menu, a way to map text or icons to actions; but detachable from the rest of the user interface.
The base trait of all user interface elements.
The base trait of all user interface elements. Subclasses belong to one
of two groups: top-level elements such as windows and dialogs, or
Component
s.
[Implementation] A UIElement automatically adds itself to the component cache on creation.
,[Java Swing] This trait does not have an exact counterpart in Java Swing. The peer is of type java.awt.Component since this is the least common upper bound of possible underlying peers.
java.awt.Component
A window with decoration such as a title, border, and action buttons.
A window with decoration such as a title, border, and action buttons.
An AWT window cannot be wrapped dynamically with this class, i.e., you cannot write something like new Window { def peer = myAWTWindow }
javax.swing.JFrame
Horizontal and vertical alignments.
Horizontal and vertical alignments. We sacrifice a bit of type-safety for simplicity here.
javax.swing.SwingConstants
Wrapper for JColorChooser.
Wrapper for JColorChooser. Publishes ColorChanged
events, when the color selection changes.
javax.swing.JColorChooser
Utility methods, mostly for wrapping components.
Simple predefined dialogs.
Simple predefined dialogs.
javax.swing.JOptionPane
Helpers for this package.
Scala-swing is a graphical user interface library that will wrap most of Java Swing for Scala in a straightforward manner.
Overview
The widget class hierarchy loosely resembles that of Java Swing. The main differences are:
java.awt.ActionListener
), a scala.swing.Reactor instance announces the interest in receiving events by callinglistenTo
for a scala.swing.Publisher. Publishers are also reactors and listen to themselves per default as a convenience. A reactor contains an objectreactions
which serves as a convenient place to register observers by adding partial functions that pattern match for any event that the observer is interested in. This is shown in the examples section below.Scala-swing comprises two main packages:
scala.swing
: All widget classes and traits.scala.swing.event
: The event hierarchy.This package object contains useful type aliases that do not have wrappers.
Examples
The following example shows how to plug components and containers together and react to a mouse click on a button: