JDK-4463949 : Window centering API required for multiscreen support
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-05-29
  • Updated: 2001-07-31
  • Resolved: 2001-07-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
1.4.0 beta2Fixed
Related Reports
Relates :  
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
Xinerama environment.

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.

X-Window, non-Xinerama:
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.

X-Window, Xinerama:
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);

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta2 FIXED IN: merlin-beta2 INTEGRATED IN: merlin-beta2

SUGGESTED FIX New method in java.awt.GraphicsEnvironment: /** * Returns the point at which centered Windows should be centered */ public Point getCenterPoint();

EVALUATION Required for cross-platform centering of Windows. Another problem encountered when attempting to center Windows is that of ensuring the Window fits on the screen - this is not always done. The problem becomes bigger in the face of systems with multiple monitors, and systems running Xinerama where Windows may need to be centered across several monitors. It is also possible that developers will want to create one huge Window which spans all available screens, yet does not conflict with the taskbar or other portions of the screen containing fixed content. To cater to both of these situations, another new method is being added to GraphicsEnvironment, getMaximumWindowBounds(). brent.christian@eng 2001-06-18