2

I am developing a toast handler to manage notifications brought to the user with a "toast" animation (slide up, stand for a while and then slide down). The Toast class extends JWindow (just for test, I could use JDialog with a more stable release).

My problem is to create a sort of clipping area to hide the toast (JWindow) at the begin of the animation. Currently the window is visible during the entire animation, but it should be hidden entirely when toast.setVisible(true); is executed and start to appear during the "slide up" phase, be entirely visible during the "stand" phase and start to disappear again during the "slide down" phase.

I don't know how to setup the clipping region, anyone can help me?

I hope that was understandable. Let me know if you need more details.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Crisoberillo
  • 171
  • 1
  • 3
  • 10

1 Answers1

2

Starting with this LowerRightFrame, use the following initial position:

int x = (int) rect.getMaxX() - f.getWidth();
int y = (int) rect.getMaxY() - f.getInsets().top;

Then use a javax.swing.Timer to periodically increase y to full height:

int y = (int) rect.getMaxY() - f.getHeight();

In this approach, the clipping is enforced by the host platform. Note that some platforms won't let a visible window be fully offscreen; without a visible drag bar, the window would be inaccessible.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045