diff options
Diffstat (limited to 'docs/examples/swing')
-rw-r--r-- | docs/examples/swing/ColorChooserDemo.scala | 61 | ||||
-rw-r--r-- | docs/examples/swing/PopupDemo.scala | 33 |
2 files changed, 94 insertions, 0 deletions
diff --git a/docs/examples/swing/ColorChooserDemo.scala b/docs/examples/swing/ColorChooserDemo.scala new file mode 100644 index 0000000000..1cb2bdefa2 --- /dev/null +++ b/docs/examples/swing/ColorChooserDemo.scala @@ -0,0 +1,61 @@ +package examples.swing + +import java.awt.{Color, Font, Dimension} +import swing._ +import event._ +import Swing._ +import BorderPanel._ + +/** + * Demo for ColorChooser. + * Based on http://download.oracle.com/javase/tutorial/uiswing/components/colorchooser.html + * + * @author andy@hicks.net + */ +object ColorChooserDemo extends SimpleSwingApplication { + def top = new MainFrame { + title = "ColorChooser Demo" + size = new Dimension(400, 400) + + contents = ui + } + + def ui = new BorderPanel { + val colorChooser = new ColorChooser { + reactions += { + case ColorChanged(_, c) => + banner.foreground = c + } + } + + colorChooser.border = TitledBorder(EtchedBorder, "Choose Text Color") + + val banner = new Label("Welcome to Scala Swing") { + horizontalAlignment = Alignment.Center + foreground = Color.yellow + background = Color.blue + opaque = true + font = new Font("SansSerif", Font.BOLD, 24) + } + + val bannerArea = new BorderPanel { + layout(banner) = Position.Center + border = TitledBorder(EtchedBorder, "Banner") + } + + // Display a color selection dialog when button pressed + val selectColor = new Button("Choose Background Color") { + reactions += { + case ButtonClicked(_) => + ColorChooser.showDialog(this, "Test", Color.red) match { + case Some(c) => banner.background = c + case None => + } + } + } + + layout(bannerArea) = Position.North + layout(colorChooser) = Position.Center + layout(selectColor) = Position.South + } +}
\ No newline at end of file diff --git a/docs/examples/swing/PopupDemo.scala b/docs/examples/swing/PopupDemo.scala new file mode 100644 index 0000000000..6a9eeb125b --- /dev/null +++ b/docs/examples/swing/PopupDemo.scala @@ -0,0 +1,33 @@ +package examples.swing + +import swing._ +import event._ +import Swing._ + +/** + * @author John Sullivan + * @author Ingo Maier + */ +object PopupDemo extends SimpleSwingApplication { + def top = new MainFrame { + 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 ButtonClicked(b) => popupMenu.show(b, 0, b.bounds.height) + case PopupMenuCanceled(m) => println("Menu " + m + " canceled.") + } + listenTo(popupMenu) + listenTo(button) + + contents = new FlowPanel(button) + } +}
\ No newline at end of file |