line 504:

r = r.getIntersection (screen);

This seems wrong to me, as unless there’s some cleverness elsewhere, it’ll collapse any window that lies outside of the viewport. I.E. if a secondary screen is removed, then screen will address the single desktop area, but if r might still be referencing the second display. The intersection then would be zero. Even in the best case scenario, the window will be shrunk, rather than relocated.

Wouldn’t it be better to just brute force it with something like:


Here, I’m assuming the screen is pre-constrained for taksbar/dock etc.


…yes, that does seem a bit wrong. My suggestion would be this:

    if (! screen.contains (r))
        r.setSize (jmin (r.getWidth(), screen.getWidth()),
                   jmin (r.getHeight(), screen.getHeight()));

        r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()),
                       jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY()));

(also untested, and probably basically the same as your code…)


That seems to be working out fine.