4

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
  • This is more of a swing question, but here is some guidance: java-forums.org/awt-swing/17138-jbutton-size.html Commented Oct 22, 2010 at 21:13
  • Well, there's a big difference between regular Swing and Scala's scala.swing wrapper libraries. Commented Oct 22, 2010 at 21:13

1 Answer 1

3

Have you tried setting a preferred size on the buttons?

buttons foreach { _.preferredSize = new Dimension(60, 60) } 
Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately, that doesn't seem to work. The buttons stay tiny.
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.
Still no luck. I ended up going back to the Java Swing libraries, which I know well. I've got it working with them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.