Package

scala

swing

Permalink

package swing

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:

Scala-swing comprises two main packages:

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:

import scala.swing._

new Frame {
  title = "Hello world"

  contents = new FlowPanel {
    contents += new Label("Launch rainbows:")
    contents += new Button("Click me") {
      reactions += {
        case event.ButtonClicked(_) =>
          println("All the colours!")
      }
    }
  }

  pack()
  centerOnScreen()
  open()
}
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. swing
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractButton extends Component with Trigger with Publisher

    Permalink

    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.

    See also

    javax.swing.AbstractButton

  2. abstract class Action extends AnyRef

    Permalink

    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.

    See also

    javax.swing.Action

  3. trait Adjustable extends Oriented

    Permalink
  4. abstract class Applet extends JApplet

    Permalink

    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.

    See also

    javax.swing.JApplet

  5. class BorderPanel extends Panel with LayoutContainer

    Permalink

    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.

    See also

    javax.swing.BorderLayout

  6. class BoxPanel extends Panel with Wrapper

    Permalink

    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.

    See also

    javax.swing.BoxLayout

  7. abstract class BufferWrapper[A] extends Buffer[A]

    Permalink

    Default partial implementation for buffer adapters.

  8. class Button extends AbstractButton with Publisher

    Permalink

    A button that can be clicked, usually to perform some action.

    A button that can be clicked, usually to perform some action.

    See also

    javax.swing.JButton

  9. class ButtonGroup extends AnyRef

    Permalink

    A button mutex.

    A button mutex. At most one of its associated buttons is selected at a time.

    See also

    javax.swing.ButtonGroup

  10. class CheckBox extends ToggleButton

    Permalink

    Two state button that can either be checked or unchecked.

    Two state button that can either be checked or unchecked.

    See also

    javax.swing.JCheckBox

  11. class CheckMenuItem extends MenuItem

    Permalink

    A menu item with a check box.

    A menu item with a check box.

    See also

    javax.swing.JCheckBoxMenuItem

  12. type Color = java.awt.Color

    Permalink
  13. class ColorChooser extends Component

    Permalink
  14. class ComboBox[A] extends Component with Publisher

    Permalink

    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.

    See also

    javax.swing.JComboBox

  15. abstract class Component extends UIElement with PeerContainer

    Permalink

    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.

    Note

    [Java Swing] Unlike in Java Swing, not all components are also containers.

    See also

    http://java.sun.com/products/jfc/tsc/articles/painting/ for the component painting mechanism

    javax.swing.JComponent

  16. trait Container extends UIElement

    Permalink

    The base traits for UI elements that can contain Components.

    The base traits for UI elements that can contain Components.

    Note

    [Java Swing] This is not the wrapper for java.awt.Container but a trait that extracts a common interface for components, menus, and windows.

  17. class DesktopPane extends Component with Wrapper

    Permalink

    A pane that can host nested internal windows (represented by InternalFrame).

  18. class Dialog extends Window with RichWindow

    Permalink

    A dialog window.

    A dialog window.

    See also

    javax.swing.JDialog

  19. type Dimension = java.awt.Dimension

    Permalink
  20. class EditorPane extends TextComponent

    Permalink

    A text component that allows multi-line text input and display.

    A text component that allows multi-line text input and display.

    See also

    javax.swing.JEditorPane

  21. class FileChooser extends Component

    Permalink

    Used to open file dialogs.

    Used to open file dialogs.

    See also

    javax.swing.JFileChooser

  22. class FlowPanel extends Panel with Wrapper

    Permalink

    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.

    See also

    java.awt.FlowLayout

  23. type Font = java.awt.Font

    Permalink
  24. class FormattedTextField extends TextComponent

    Permalink

    A text field with formatted input.

    A text field with formatted input.

    See also

    javax.swing.JFormattedTextField

  25. class Frame extends Window with RichWindow

    Permalink

    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 }

    See also

    javax.swing.JFrame

  26. type Graphics2D = java.awt.Graphics2D

    Permalink
  27. class GridBagPanel extends Panel with LayoutContainer

    Permalink

    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.

    See also

    java.awt.GridBagLayout

  28. class GridPanel extends Panel with Wrapper

    Permalink

    A panel that lays out its contents in a uniform grid.

    A panel that lays out its contents in a uniform grid.

    See also

    java.awt.GridLayout

  29. type Image = java.awt.Image

    Permalink
  30. type Insets = java.awt.Insets

    Permalink
  31. class InternalFrame extends Component with RootPanel with Publisher

    Permalink

    A window that can be nested inside another window (typically within a DesktopPane).

  32. class Label extends Component

    Permalink

    A label component that display either a text, an icon, or both.

    A label component that display either a text, an icon, or both.

    See also

    javax.swing.JLabel

  33. trait LayoutContainer extends Wrapper

    Permalink

    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.

    Note

    [Java Swing] In scala.swing, panels and layout managers are combined into subclasses of this base class. This approach allows for typed component constraints.

  34. class ListView[A] extends Component

    Permalink

    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

    See also

    javax.swing.JList

  35. class MainFrame extends Frame

    Permalink

    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.

  36. abstract class MapWrapper[K, V] extends Map[K, V]

    Permalink

    Default partial implementation for mutable map adapters.

  37. class Menu extends MenuItem with Wrapper

    Permalink

    A menu.

    A menu. Contains menu items. Being a menu item itself, menus can be nested.

    See also

    javax.swing.JMenu

  38. class MenuBar extends Component with Wrapper

    Permalink

    A menu bar.

    A menu bar. Each window can contain at most one. Contains a number of menus.

    See also

    javax.swing.JMenuBar

  39. class MenuItem extends AbstractButton

    Permalink

    A menu item that can be used in a menu.

    A menu item that can be used in a menu.

    See also

    javax.swing.JMenuItem

  40. trait Orientable extends Oriented

    Permalink

    An Oriented whose orientation can be changed.

    An Oriented whose orientation can be changed.

  41. trait Oriented extends AnyRef

    Permalink

    Something that can have an orientation.

  42. abstract class Panel extends Component with Wrapper

    Permalink

    A component that can contain other components.

    A component that can contain other components.

    See also

    javax.swing.JPanel

  43. class PasswordField extends TextField

    Permalink

    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.

    See also

    javax.swing.JPasswordField

  44. type Point = java.awt.Point

    Permalink
  45. class PopupMenu extends Component with Wrapper with Publisher

    Permalink

    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)
    See also

    javax.swing.JPopupMenu

  46. class ProgressBar extends Component with Orientable

    Permalink

    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.

    See also

    javax.swing.JProgressBar

  47. trait Publisher extends Reactor

    Permalink

    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.

  48. class RadioButton extends ToggleButton

    Permalink

    A two state button that is usually used in a ButtonGroup together with other RadioButtons, 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 RadioButtons, in order to indicate that at most one of them can be selected.

    See also

    javax.swing.JRadioButton

  49. class RadioMenuItem extends MenuItem

    Permalink

    A menu item with a radio button.

    A menu item with a radio button.

    See also

    javax.swing.JRadioButtonMenuItem

  50. abstract class Reactions extends Reaction

    Permalink

    Used by reactors to let clients register custom event reactions.

  51. trait Reactor extends AnyRef

    Permalink

    The counterpart to publishers.

    The counterpart to publishers. Listens to events from registered publishers.

  52. type Rectangle = java.awt.Rectangle

    Permalink
  53. sealed trait RichWindow extends Window

    Permalink

    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.

  54. trait RootPanel extends Container

    Permalink

    The root of a component hierarchy.

    The root of a component hierarchy. Contains at most one component.

    See also

    javax.swing.RootPaneContainer

  55. class ScrollBar extends Component with Orientable with Wrapper

    Permalink
  56. class ScrollPane extends Component with Container

    Permalink

    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.

    See also

    javax.swing.JScrollPane

  57. trait Scrollable extends Component

    Permalink

    A component that is specially suitable for being placed inside a ScrollPane.

    A component that is specially suitable for being placed inside a ScrollPane.

    See also

    javax.swing.Scrollable

  58. class Separator extends Component with Oriented

    Permalink

    A bar that can be used a separator, most commonly in menus.

    A bar that can be used a separator, most commonly in menus.

    See also

    javax.swing.JSeparator

  59. trait SequentialContainer extends Container

    Permalink

    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.

  60. abstract class SetWrapper[A] extends Set[A]

    Permalink

    Default partial implementation for mutable set adapters.

  61. abstract class SimpleSwingApplication extends SwingApplication

    Permalink

    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.

  62. class Slider extends Component with Orientable with Publisher

    Permalink

    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.

    See also

    javax.swing.JSlider

  63. class SplitPane extends Component with Container with Orientable

    Permalink

    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.

    See also

    javax.swing.JSplitPane

  64. abstract class SwingApplication extends Reactor

    Permalink

    Convenience class with utility methods for GUI applications.

  65. class TabbedPane extends Component with Publisher

    Permalink

    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.

    See also

    javax.swing.JTabbedPane

  66. class Table extends Component with Wrapper

    Permalink

    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.

    See also

    javax.swing.JTable

  67. class TextArea extends TextComponent with HasColumns with HasRows

    Permalink

    A text component that allows multi-line text input and display.

    A text component that allows multi-line text input and display.

    See also

    javax.swing.JTextArea

  68. class TextComponent extends Component with Publisher

    Permalink

    A component that allows some kind of text input and display.

    A component that allows some kind of text input and display.

    See also

    javax.swing.JTextComponent

  69. class TextField extends TextComponent with HasColumns with Trigger

    Permalink

    A text component that allows single line text input and display.

    A text component that allows single line text input and display.

    See also

    javax.swing.JTextField

  70. class TextPane extends TextComponent

    Permalink

    A text component used to model styled paragraphs of text.

    A text component used to model styled paragraphs of text.

    See also

    javax.swing.JTextPane

  71. class ToggleButton extends AbstractButton

    Permalink

    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.

    See also

    javax.swing.JToggleButton

  72. class ToolBar extends Component with Wrapper

    Permalink

    Like a menu, a way to map text or icons to actions; but detachable from the rest of the user interface.

  73. trait UIElement extends Proxy with LazyPublisher

    Permalink

    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 Components.

    Note

    [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.

    See also

    java.awt.Component

  74. abstract class Window extends UIElement with RootPanel with PeerContainer with Publisher

    Permalink

    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 }

    See also

    javax.swing.JFrame

Value Members

  1. object Action

    Permalink
  2. object Adjustable

    Permalink
  3. object Alignment extends Enumeration

    Permalink

    Horizontal and vertical alignments.

    Horizontal and vertical alignments. We sacrifice a bit of type-safety for simplicity here.

    See also

    javax.swing.SwingConstants

  4. object BorderPanel

    Permalink
  5. object Button

    Permalink
  6. object ColorChooser

    Permalink

    Wrapper for JColorChooser.

    Wrapper for JColorChooser. Publishes ColorChanged events, when the color selection changes.

    See also

    javax.swing.JColorChooser

  7. object ComboBox

    Permalink
  8. object Component

    Permalink

    Utility methods, mostly for wrapping components.

  9. object Container

    Permalink
  10. object DesktopPane

    Permalink
  11. object Dialog

    Permalink

    Simple predefined dialogs.

    Simple predefined dialogs.

    See also

    javax.swing.JOptionPane

  12. object FileChooser

    Permalink
  13. object FlowPanel

    Permalink
  14. object Font

    Permalink
  15. object FormattedTextField

    Permalink
  16. object GridBagPanel

    Permalink
  17. object GridPanel

    Permalink
  18. object ListView

    Permalink
  19. object MenuBar

    Permalink
  20. object Orientation extends Enumeration

    Permalink
  21. object Reactions

    Permalink
  22. object RichWindow

    Permalink
  23. object ScrollBar

    Permalink
  24. object ScrollPane

    Permalink
  25. object Scrollable

    Permalink
  26. object SequentialContainer

    Permalink
  27. object Swing

    Permalink

    Helpers for this package.

  28. object TabbedPane

    Permalink
  29. object Table

    Permalink
  30. object TextComponent

    Permalink
  31. object UIElement

    Permalink
  32. package event

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped