Skip to content

Commit 722a2a3

Browse files
author
Allan Jacobs
committed
Fix up borders, x-alignments, and RigidBoxes that were in the original. One bug fix in the handler for the Set button that showed up when the button is clicked without choosing a name in the list.
1 parent 3e5040b commit 722a2a3

File tree

1 file changed

+13
-6
lines changed
  • examples/src/main/scala/scala/swing/examples/tutorials/components

1 file changed

+13
-6
lines changed

examples/src/main/scala/scala/swing/examples/tutorials/components/ListDialog.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ class ListDialog(frame: Frame, locationComp: Component,
106106
}
107107

108108
val buttonPane = new BoxPanel(Orientation.Horizontal) {
109-
border = Swing.EmptyBorder(0, 10, 10, 10)
109+
border = Swing.EmptyBorder(10, 10, 10, 10)
110110
contents += Swing.HGlue
111111
contents += cancelButton
112-
contents += Swing.HGlue
112+
contents += Swing.RigidBox(new Dimension(10, 0))
113113
contents += setButton
114114
}
115115

@@ -127,7 +127,7 @@ class ListDialog(frame: Frame, locationComp: Component,
127127
listenTo(list.mouse.clicks)
128128
reactions += {
129129
case ButtonClicked(`setButton`) =>
130-
setValue(list.listData(list.selection.leadIndex))
130+
if (list.selection.leadIndex >= 0) setValue(list.listData(list.selection.leadIndex))
131131
visible = false
132132
case ButtonClicked(`cancelButton`) =>
133133
setValue(initialValue)
@@ -177,17 +177,20 @@ class ListDialogRunner(frame: Frame) extends BoxPanel(Orientation.NoOrientation)
177177
"Otto", "Ringo", "Rocco", "Rollo")
178178

179179
//Create the labels.
180-
val intro = new Label("The chosen name:")
180+
val intro = new Label("The chosen name:") {
181+
xLayoutAlignment = java.awt.Component.CENTER_ALIGNMENT
182+
}
181183
val nameLabel = new Label(names(1)) {
182184
//Use a wacky font if it exists. If not, this falls
183185
//back to a font we know exists.
184186
font = getAFont
187+
xLayoutAlignment = java.awt.Component.CENTER_ALIGNMENT
185188
}
186189
intro.peer.setLabelFor(nameLabel.peer)
187190

188191
//Create the button.
189192
val button = new Button("Pick a new name...") {
190-
193+
xLayoutAlignment = java.awt.Component.CENTER_ALIGNMENT
191194
}
192195

193196
listenTo(button)
@@ -205,9 +208,13 @@ class ListDialogRunner(frame: Frame) extends BoxPanel(Orientation.NoOrientation)
205208

206209
}
207210

208-
211+
border = Swing.EmptyBorder(20, 20, 10, 20)
212+
//Add the labels to the content pane.
209213
contents += intro
214+
contents += Swing.VStrut(5)
210215
contents += nameLabel
216+
//Add a vertical spacer that also guarantees us a minimum width:
217+
contents += Swing.RigidBox(new Dimension(150, 10))
211218
contents += button
212219

213220

0 commit comments

Comments
 (0)