0

scala-swing ウィンドウの位置を変更したい。初期化時に場所の設定が正しく機能することがわかりましたが、場所を動的に変更することはできません

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
  }
}

どうすればいいですか?

4

1 に答える 1

0

次のステートメントを使用して実現できます。

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

これthis.peerはJava JButtonへの参照getRootPaneであり、ボタンのプレースホルダーを提供し、この特定のケースではオブジェクトgetParentを取得します(階層が大きい場合はMainFrame複数を使用する必要がある場合があります)。使用することで、API で禁止されている可能性のある新しいものを作成しようとしているとgetParent思います。top.locationMainFrame

于 2015-12-11T10:09:35.253 に答える