Minimizing to tray is quite easy, when you use a WindowListener:
This will really hide the window right after it has been minimized (called iconified in
Java).
Restoring is not that different:
The first line retrieves the current state, which is a bitmask. It then sets the ICONIFIED (minimized) part to false, then sets the same state again. This way, if the program was maximized before it will be maximimized again, etc. Of course a setVisible(true) must follow to show the window again.