The centering of windows on multi-head systems running Xinerama has caused some troubles, such as
the following Solaris bugs:
4267592 : Need ability to determine physical screen layout for Xinerama aware applications.
4261921 : Xinerama headers should be added to SUNWxwinc
4293551 : dtsession in xinerama mode should (optionally) not center the logout dialog box
4356114 : Screen layout has non-readable centered dialog on multi-headed system
The problem is this: some people use displays that have no "borders", which can be butted up
against one another such that it is difficult to tell that there are multiple monitors rather than
one large display. Such users want windows centered in the middle of the Xinerama virtual
coordinate space. This often means a "properly" centered window will span multiple screens. Many
multi-mon users, though, have regular CRT monitors, with several inches of "packaging" between the
actual display areas. In this case, a window spanning multiple screens is a disconcerting effect,
especially if the window cannot be dragged onto one monitor or the other (the Solaris login
screen, for instance). In short, there is (or was) no way to tell where to center a window in a
The X group has added some API to resolve the problem. See Comments and PSARC/2000/036. This new API allows Xinerama users to specify where they want "centered" windows to be centered, and allows developers of Xinerama-aware applications to code their apps accordingly.
Many changes in JDK 1.4 have made Java more Xinerama-aware, including bug 4356756. The fix for this bug will return all screen devices when running on a Xinerama system; pre-1.4 returns only a single GraphicsDevice.
The pre-1.4 way to center a window has been to center it within the bounds of the default
GraphicsDevice, something like this:
bounds = getDefaultScreenDevice().getDefaultConfiguration().getBounds();
frame.setLocation(bounds / 2 - size of window / 2);
On pre-1.4 JDKs, this code would center the windows "correctly" on Xinerama systems where windows
should be centered to then entire Xinerama coordinate space.
1.4, post 4356756-fix JDKs will center windows "correctly" on Xinerama systems where windows
should be centered within the first display.
At present, there is no Java API to correctly center a window on all platforms. Given that there
is now a way for Xinerama users to specify window centering through X resources, I propose that we
also advertise this through a new method in GraphicsEnvironment:
public Point getCenterPoint();
(or maybe getCenteringPoint())
This method would work as follows on various platforms:
These platforms include all monitors in a single virtual coordinate space. However, there is one
"primary" display (on Win32 the primary display contains the task bar, on the Mac, the menubar).
This method would return the coordinates of the center of the primary display.
Each display has its own coordinate system; the upper-left corner of every display is 0,0. Again,
there is a "first" display. This method would return the center point of the primary display.
All monitors share a single virtual coordinate space, as on Win32. However, it is possible for
the user to specify through X resources where windows should be centered. If these resources are
set, getCenterPoint() will reflect their value. Otherwise, it will return the point at the center
of the virtual coordinate space. (In practice, this will almost always be set - CDE sets it by
The correct 1.4 code for centering windows would be:
frame.setLocation(getCenterPoint() - size of window / 2);