0

I'm trying to display an image in a SimpleSwingApplication. I would like to make the image change size when the window changes size (i.e. manually dragging the cursor to adjust size).

I think this is done by listening for something, then reacting with UIElementResized.

But I'm not sure how to actually do it.

I've tried:

        listenTo(top) \\ or Window/Frame/UIEvent
        reactions += {
            // case UIElementResized=>
            case class UIElementResized(source: UIElement); => // or without the semicolon, without "source: UIElement", without "class", and a few other permutations.
               println(size) 
        }

I asked a similar question yesterday, but it was narrow. I want to make a more broad question about the entire problem.

Jones
  • 1,154
  • 1
  • 10
  • 35
  • well, you definitely want to do `case UIElementResized(source) =>` this is your valid permutation. `case UIElementResized(source: UIElement) =>` is fine as well. I am only adressing pattern matching thing, I don't know about swing though. – Łukasz Apr 19 '16 at 20:18

1 Answers1

0

I'm not familiar with Swing, but it looks like reactions use partial functions as callbacks. So the issue is in your pattern matching syntax, try

reactions += {
    case UIElementResized(source) => println(source.size)
}

You can find more detailed examples here: Listeners and reactions in Scala Swing

Community
  • 1
  • 1
Vitalii Kotliarenko
  • 2,947
  • 18
  • 26