views:

32

answers:

1

Scala is an awesome language, but unfortunately the library documentation is lacking. How do I change the initial size of a component? I have nothing on it (intentionally), but would like it to be a certain size anyway. I currently have

...
contents = new BoxPanel(Orientation.Vertical) {
    contents += new BoxPanel(Orientation.Horizontal) {
        contents += buttons(0)
        contents += buttons(1)
        contents += buttons(2)
    }
    contents += new BoxPanel(Orientation.Horizontal) {
        contents += buttons(3)
        contents += buttons(4)
        contents += buttons(5)
    }
    contents += new BoxPanel(Orientation.Horizontal) {
        contents += buttons(6)
        contents += buttons(7)
        contents += buttons(8)
    }
    border = Swing.EmptyBorder(10, 10, 10, 10);
}
...

buttons is an array of scala.swing.Buttons. Unfortunately they all show up very small when the application is run. I'd like them to be about 60x60 pixels each, though any reasonably large square would suffice.

+2  A: 

Have you tried setting a preferred size on the buttons?

buttons foreach { _.preferredSize = new Dimension(60, 60) }
Aaron Novstrup
Unfortunately, that doesn't seem to work. The buttons stay tiny.
alpha123
Sounds like a problem with the layout. You could try setting the preferredSize when you construct each button (e.g. `new Button { preferredSize = new Dimension(60, 60)`) or revalidating the outer BoxPanel after you set the preferred sizes.
Aaron Novstrup
Still no luck. I ended up going back to the Java Swing libraries, which I know well. I've got it working with them.
alpha123