Scala.use(better,Swing); TabbedPaneDemo
《前の記事|記事一覧|次の記事》
Scala.use(better,Swing)
Using Swing ComponentsTabbedPaneDemo
☞ Java Tutorials Sample Code を Scala で再構成しました
《参考記事》
- How to Use Tabbed Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
- Java Tutorials Sample Code, TabbedPaneDemo.java
《関連記事》-
- TabbedPaneDemo: Java 版
- TabbedPaneDemo: Scala 版
- TabbedPaneDemo: Jython 版
■ Scala 版
1: /* 2: * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 3: * ---------------------------------------- 4: * Copyleft (c) 2010-2013, KOTSUBU-chan and/or its affiliates. 5: */ 6: package components 7: 8: // ---------------------------------------- 9: import swing._ 10: object TabbedPaneDemo extends MainFrame { 11: val version = TabbedPaneDemo 12: .getClass.getName+": #1.0.01" 13: // ---------------------------------------- 14: title = "TabbedPaneDemo" 15: contents = new TabbedPaneDemo 16: peer.setLocationRelativeTo(null) 17: } 18: 19: // ---------------------------------------- 20: class TabbedPaneDemo extends GridPanel(1,1) { 21: import TabbedPane._ 22: val tabbedPane: TabbedPane = new TabbedPane() { 23: import swing.event._ 24: pages += new Page(tabbedPane, "Tab 1", 25: makeTextPanel("Panel #1"), 26: "Does nothing") { 27: mnemonic = Key.Key1.id 28: } 29: pages += new Page(tabbedPane, "Tab 2", 30: makeTextPanel("Panel #2"), 31: "Does twice as much nothing") { 32: mnemonic = Key.Key2.id 33: } 34: pages += new Page(tabbedPane, "Tab 3", 35: makeTextPanel("Panel #3"), 36: "Still does nothing") { 37: mnemonic = Key.Key3.id 38: } 39: val panel4 = makeTextPanel( 40: "Panel #4 (has a preferred size of 410 x 50).") 41: panel4.preferredSize = new Dimension(410, 50) 42: pages += new Page(tabbedPane, "Tab 4", 43: panel4, 44: "Does nothing at all") { 45: mnemonic = Key.Key4.id 46: } 47: val icon = createImageIcon("images/middle.gif") 48: 0 to pages.length-1 foreach { peer.setIconAt(_, icon) } 49: contents += this 50: tabLayoutPolicy = Layout.Scroll 51: } 52: def makeTextPanel(text: String) = new GridPanel(1, 1) { 53: contents += new Label(text) { 54: horizontalAlignment = Alignment.Center 55: } 56: } 57: import javax.swing.ImageIcon 58: def createImageIcon(path: String): ImageIcon = { 59: val imgURL = TabbedPaneDemo.getClass.getResource(path) 60: if (imgURL != null) { 61: new ImageIcon(imgURL) 62: } else { 63: System.err.println("Couldn't find file: " + path) 64: null 65: } 66: } 67: } 68: 69: // EOF
↑ TOP
update*13/03/08 12:59:32