summaryrefslogtreecommitdiff
path: root/docs/examples/swing/GridBagDemo.scala
blob: 60cfc13acb76d4065bee113ec1ef225c6b52f5d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package examples.swing

import swing._
import swing.event._
import GridBagPanel._
import java.awt.Insets

object GridBagDemo extends SimpleSwingApplication {
  lazy val ui = new GridBagPanel {
    val c = new Constraints
    val shouldFill = true
    if (shouldFill) {
      c.fill = Fill.Horizontal
    }

    val button1 = new Button("Button 1")

    c.weightx = 0.5

    c.fill = Fill.Horizontal
    c.gridx = 0;
    c.gridy = 0;
    layout(button1) = c

    val button2 = new Button("Button 2")
    c.fill = Fill.Horizontal
    c.weightx = 0.5;
    c.gridx = 1;
    c.gridy = 0;
    layout(button2) = c

    val button3 = new Button("Button 3")
    c.fill = Fill.Horizontal
    c.weightx = 0.5;
    c.gridx = 2;
    c.gridy = 0;
    layout(button3) = c

    val button4 = new Button("Long-Named Button 4")
    c.fill = Fill.Horizontal
    c.ipady = 40;      //make this component tall
    c.weightx = 0.0;
    c.gridwidth = 3;
    c.gridx = 0;
    c.gridy = 1;
    layout(button4) = c

    val button5 = new Button("5")
    c.fill = Fill.Horizontal
    c.ipady = 0;       //reset to default
    c.weighty = 1.0;   //request any extra vertical space
    c.anchor = Anchor.PageEnd
    c.insets = new Insets(10,0,0,0);  //top padding
    c.gridx = 1;       //aligned with button 2
    c.gridwidth = 2;   //2 columns wide
    c.gridy = 2;       //third row
    layout(button5) = c
  }

  def top = new MainFrame {
    title = "GridBag Demo"
    contents = ui
  }
}