scala
package scala
- Alphabetic
- By Inheritance
- scala
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Package Members
- package swing
Scala-swing is a graphical user interface library that will wrap most of Java Swing for Scala in a straightforward manner.
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:
- In Java Swing all components are containers per default. This does not make much sense for a number of components, like scala.swing.TextField, scala.swing.CheckBox, scala.swing.RadioButton, and so on. Our guess is that this architecture was chosen because Java lacks multiple inheritance. In scala-swing, components that can have child components extend the scala.swing.Container trait.
- Layout managers and panels are coupled. There is no way to exchange the layout manager of a panel. As a result, the layout constraints for widgets can be typed. (Note that you gain more type-safety and do not loose much flexibility here. Besides being not a common operation, exchanging the layout manager of a panel in Java Swing almost always leads to exchanging the layout constraints for every of the panel's child component. In the end, it is not more work to move all children to a newly created panel.)
- Widget hierarchies are built by adding children to their parent container's contents collection. The typical usage style is to create anonymous subclasses of the widgets to customize their properties, and nest children and event reactions.
- The scala-swing event system follows a different approach than the underlying Java system. Instead
of adding event listeners with a particular interface (such as
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. - For more details see SIP-8.
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:
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() }
Type Members
- type ::[A] = scala.collection.immutable.::[A]
- type AbstractMethodError = java.lang.AbstractMethodError
- type AnyRef = AnyRef
- type ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBoundsException
- type BigDecimal = scala.math.BigDecimal
- type BigInt = scala.math.BigInt
- type ClassCastException = java.lang.ClassCastException
- type Cloneable = java.lang.Cloneable
- type Either[+A, +B] = scala.util.Either[A, B]
- type Equiv[T] = scala.math.Equiv[T]
- type Error = java.lang.Error
- type Exception = java.lang.Exception
- type Fractional[T] = scala.math.Fractional[T]
- type IllegalArgumentException = java.lang.IllegalArgumentException
- type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
- type IndexedSeq[+A] = scala.collection.immutable.IndexedSeq[A]
- Annotations
- @migration
- Migration
(Changed in version 2.13.0) scala.IndexedSeq is now scala.collection.immutable.IndexedSeq instead of scala.collection.IndexedSeq
- type Integral[T] = scala.math.Integral[T]
- type InterruptedException = java.lang.InterruptedException
- type Iterable[+A] = scala.collection.Iterable[A]
- type IterableOnce[+A] = scala.collection.IterableOnce[A]
- type Iterator[+A] = scala.collection.Iterator[A]
- type LazyList[+A] = scala.collection.immutable.LazyList[A]
- type Left[+A, +B] = scala.util.Left[A, B]
- type List[+A] = scala.collection.immutable.List[A]
- type NoSuchElementException = java.util.NoSuchElementException
- type NullPointerException = java.lang.NullPointerException
- type NumberFormatException = java.lang.NumberFormatException
- type Numeric[T] = scala.math.Numeric[T]
- type Ordered[T] = scala.math.Ordered[T]
- type Ordering[T] = scala.math.Ordering[T]
- type PartialOrdering[T] = scala.math.PartialOrdering[T]
- type PartiallyOrdered[T] = scala.math.PartiallyOrdered[T]
- type Range = scala.collection.immutable.Range
- type Right[+A, +B] = scala.util.Right[A, B]
- type RuntimeException = java.lang.RuntimeException
- type Seq[+A] = scala.collection.immutable.Seq[A]
- Annotations
- @migration
- Migration
(Changed in version 2.13.0) scala.Seq is now scala.collection.immutable.Seq instead of scala.collection.Seq
- type Serializable = java.io.Serializable
- type StringBuilder = scala.collection.mutable.StringBuilder
- type StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException
- type Throwable = java.lang.Throwable
- type UnsupportedOperationException = java.lang.UnsupportedOperationException
- type Vector[+A] = scala.collection.immutable.Vector[A]
Deprecated Type Members
- type BufferedIterator[+A] = scala.collection.BufferedIterator[A]
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use scala.collection.BufferedIterator instead of scala.BufferedIterator
- type Stream[+A] = scala.collection.immutable.Stream[A]
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use LazyList instead of Stream
- type Traversable[+A] = scala.collection.Iterable[A]
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use Iterable instead of Traversable
- type TraversableOnce[+A] = scala.collection.IterableOnce[A]
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use IterableOnce instead of TraversableOnce
Value Members
- val +:: scala.collection.+:.type
- val :+: scala.collection.:+.type
- val ::: scala.collection.immutable.::.type
- val AnyRef: Specializable
- val BigDecimal: scala.math.BigDecimal.type
- val BigInt: scala.math.BigInt.type
- val Either: scala.util.Either.type
- val Equiv: scala.math.Equiv.type
- val Fractional: scala.math.Fractional.type
- val IndexedSeq: scala.collection.immutable.IndexedSeq.type
- val Integral: scala.math.Integral.type
- val Iterable: scala.collection.Iterable.type
- val Iterator: scala.collection.Iterator.type
- val LazyList: scala.collection.immutable.LazyList.type
- val Left: scala.util.Left.type
- val List: scala.collection.immutable.List.type
- val Nil: scala.collection.immutable.Nil.type
- val Numeric: scala.math.Numeric.type
- val Ordered: scala.math.Ordered.type
- val Ordering: scala.math.Ordering.type
- val Range: scala.collection.immutable.Range.type
- val Right: scala.util.Right.type
- val Seq: scala.collection.immutable.Seq.type
- val StringBuilder: scala.collection.mutable.StringBuilder.type
- val Vector: scala.collection.immutable.Vector.type