余録:worldCup/scala/ex06/wcFrame.scala

  1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
  2: 
  3: /* ---------------------------------------- demo: scala
  4: cd /Users/sketch/home_sketch/worldCup/scala/
  5: 
  6: scalac ex06/wcFrame.scala
  7: scala WorldCup
  8: */
  9: 
 10: // ----------------------------------------
 11: import swing._
 12: 
 13: object WorldCup extends SimpleSwingApplication {
 14:   println("version: #1.0.33")
 15: 
 16:   def top = new MainFrame {
 17:     title = "FIFA World Cup #06"
 18:     contents = TopPanel
 19:   }
 20: }
 21: 
 22: // ----------------------------------------
 23: import javax.swing.ImageIcon
 24: 
 25: object TopPanel extends FlowPanel {
 26:   def _leftComponent = {
 27:     def view = new Label {
 28:       icon = new ImageIcon("matches/wc2010logo.png")
 29:       text = "2010 FIFA World Cup South Africa"
 30:       horizontalAlignment = Alignment.Center
 31:       verticalTextPosition = Alignment.Top
 32:       horizontalTextPosition = Alignment.Center
 33:     }
 34:     new ScrollPane {
 35:       viewportView = view
 36:       preferredSize = new Dimension(120,150)
 37:     }
 38:   }
 39: 
 40:   def _rightComponent = {
 41:     def view = new Label {
 42:       icon = new ImageIcon("matches/fifa.png")
 43:     }
 44:     new ScrollPane {
 45:       viewportView = view
 46:       preferredSize = new Dimension(180,0)
 47:     }
 48:   }
 49:   contents += new SplitPane {
 50:     orientation = Orientation.Vertical
 51:     oneTouchExpandable = true
 52:     dividerLocation = 100
 53:     leftComponent  = _leftComponent
 54:     rightComponent = _rightComponent
 55:   }
 56: }
 57: 
 58: // ========================================

Java の素描 #006: スクロールバーを利用する

記事一覧 Java.use(better, Swing=Scala) #FIFA World Cup への道《Scala2.8.0》

Java の素描 Scala 弾丸ツアー:時短プログラミング生活のすすめ 〜

《著》小粒ちゃん@湘南組《監修》タマゴ倶楽部

第1版♪2003/05/23 ● 第2版♪2006/04/03 ● 第3版♪2010/06/11● 第4版♪2010/07/14

》作業中です《

step06: スクロールバーを利用する

スクロールバーを利用すると、限られた領域でコンポーネントを表示できます。

from javax.swing import JScrollPane
...
class TopPanel(JPanel):
    def __init__(self, master, *args, **keys):
        ...
        def leftComponent():
            view = JLabel(
                ...
                preferredSize = (120, 150),
                )
            comp = JScrollPane(
                viewportView = view,
                preferredSize = (120,150),
                )
            return comp

        def rightComponent():
            view = JLabel(
                ...
                preferredSize = (180, 0),
                )
            comp = JScrollPane(
                viewportView = view,
                preferredSize = (180,0),
                )
            return comp
        ...
        self.add(comp)
        master.pack()

分割した枠の左側にはラベル(テキストと画像)が、右側にはアイコン画像が表示されます。


スクルールバーを操作すると、隠れた部分まで見らます。


TOP
》作業中です《

関連記事


Last updated♪2010/08/13