Swingbuilder - Application Location Centralization

I am creating an application using Griffon-> SwingBuilder. I would like to be able to center the application on the desktop.

I know that we have the argument "location: [x, y]", which we can provide when creating the application. Is there any way to access the properties of the desktop to calculate the center?

+3
source share
2 answers

For various reasons, you cannot do this inline. Here is one way to focus.

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

, , , node . , :

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

( - node).

+3

Swing , ( )

0

Source: https://habr.com/ru/post/1742834/


All Articles