0

I want to change scala-swing window location. I found setting location works correctly when initialization but can't change location dynamically

import java.awt.Point

import scala.swing._
import scala.swing.event.ButtonClicked

object TestWindow extends SimpleSwingApplication {
  def top = new MainFrame {
    contents = new BoxPanel(Orientation.Vertical) {
      contents += new Button("Change location") {
        reactions += {
          case e: ButtonClicked => {
            println("change location")
            top.location = new Point(200, 100)//doesn't work
            println("change location end")
          }
        }
      }
    }
    location = new Point(100, 50) //works correctly
  }
}

How can I do it?

Loran
  • 223
  • 2
  • 15

1 Answers1

0

It can be achieved using following statement:

this.peer.getRootPane.getParent.setLocation(new Point(200, 100))

here this.peer is reference to java JButton, getRootPane gives you placeholder of the button, then in this particular case getParent gets your MainFrame object (may need to use more than one getParent if hierachy is bigger). I think by using top.location you are trying to create a new MainFrame which is likely to be prohibited by API.

e_z
  • 60
  • 6