我正在使用Griffon->SwingBuilder创建一个应用程序。我希望能够在桌面上居中显示应用程序。
我知道我们可以在创建应用程序时提供'location: x,y‘参数。有没有什么方法可以访问桌面属性来计算中心?
发布于 2010-04-27 06:36:44
由于各种原因,你不能做内联。这里有一种居中的方法
import java.awt.*
import groovy.swing.*
sb = new SwingBuilder()
sb.build {
f = frame(pack:true) {
label "<html>" + (("This is a very long label."*3) + "<BR>")*5
}
Point cp = GraphicsEnvironment.localGraphicsEnvironment.centerPoint
f.location = new Point((int)(cp.x - f.width), (int) (cp.y - f.height))
f.show()
}不能在属性中设置它的原因是,在计算属性时,尚未在任何地方创建或存储子节点。一种替代方法是将其设置为子内容块的一部分:
frame(show:true)
{
label "<html>" + (("This is a very long label."*3) + "<BR>")*5
current.pack()
Point cp = GraphicsEnvironment.localGraphicsEnvironment.centerPoint
current.location = new Point((int)(cp.x -current.width/2), (int)(cp.y - current.height/2))
}(current是包含节点的元变量)。
发布于 2010-04-27 05:06:07
Swing的一个特性是,它可以记住最后一个位置和大小(如果可以调整大小)
https://stackoverflow.com/questions/2714314
复制相似问题