Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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
- }
- }
- }
Add Comment
Please, Sign In to add comment