Skip to content

Instantly share code, notes, and snippets.

@mpen
Created October 24, 2009 10:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpen/217465 to your computer and use it in GitHub Desktop.
Save mpen/217465 to your computer and use it in GitHub Desktop.
ScalaでSwing メニュー
// ScalaでSwing メニュー
import scala.swing._
import scala.swing.event.WindowClosing
import java.awt.event.{ KeyEvent, InputEvent }
import javax.swing.{ KeyStroke, ImageIcon }
object ScalaSwingMenu extends SimpleGUIApplication {
def top = new MainFrame {
title = "ScalaでSwing メニュー"
size = (600, 400)
// contents = new Label() { icon = new ImageIcon("icon.png") }
// メニュー
val menuFile = new Menu("メニュー(M)")
//TODO menuFile.mnemonic = Key.M
val menuOpen = new MenuItem(new Action("開く(O)") {
mnemonic = KeyEvent.VK_O
accelerator = Some(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK))
icon = new ImageIcon("build/icon.png")
toolTip = "ファイルを開く"
def apply() {}
})
val menuSave = new MenuItem(new Action("保存(S)") {
mnemonic = KeyEvent.VK_S
accelerator = Some(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK))
enabled = false
def apply() {}
})
val menuLine = new CheckMenuItem("行番号を表示")
val menuLang = new Menu("言語(L)")
val menuLangScala = new RadioMenuItem("Scala")
val menuLangRuby = new RadioMenuItem("Ruby")
val mutexLang = new ButtonGroup(menuLangScala, menuLangRuby)
menuLang.contents ++= mutexLang.buttons
val menuExit = new MenuItem(new Action("終了(X)") {
mnemonic = KeyEvent.VK_X
def apply() {
top.publish(new WindowClosing(top))
}
})
menuFile.contents += menuOpen
menuFile.contents += menuSave
menuFile.contents += menuLine
menuFile.contents += menuLang
menuFile.contents += new Separator
menuFile.contents += menuExit
menuBar = new MenuBar {
contents += menuFile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment