1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
2: /*
3: * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
4: */
5: package components
6:
7: import java.awt.GridBagConstraints
8: import swing._
9: import swing.event._
10: import GridBagPanel._
11:
12: // ----------------------------------------
13: object TextDemo {
14: val version = TextDemo
15: .getClass.getName+": #1.0.10a"
16: }
17:
18: // ----------------------------------------
19: class TextDemo extends GridBagPanel {
20: // implements ActionListener
21:
22: val textField = new TextField(20) {
23: Command.listenTo(this)
24: }
25:
26: val textArea = new TextArea(5, 20) {
27: editable = false
28: }
29: val scrollPane = new ScrollPane(textArea)
30:
31: //Add Components to this panel.
32: new Constraints {
33: gridwidth = GridBagConstraints.REMAINDER
34: fill = Fill.Horizontal
35: add(textField, this)
36: }
37:
38: new Constraints {
39: gridwidth = GridBagConstraints.REMAINDER
40: fill = Fill.Both
41: weightx = 1.0
42: weighty = 1.0
43: add(scrollPane, this)
44: }
45:
46: // ----------------------------------------
47: object Command extends Publisher {
48: reactions += {
49: case EditDone(source) =>
50: val text = source.text
51: textArea.append("%s\n" format text)
52: textField.selectAll
53: textArea.caret.position = textArea.peer.getDocument().getLength()
54: }
55: }
56: }
57:
58: // ========================================