toolkit.getScreenInsets() is used by clients in conjunction with screen
bounds to position components on screen so they do not overlap the dock or
task bar.
However, if the dock location changes when the component is up, the insets
retrieved by this call do not reflect the new reality.
Test case:
Run the following code. Press the button that appears on screen and note the
insets.
With the app still running, change the dock position in the OS
Press the button again. The insets do not reflect the location of the dock.
Restart app, the insets are now updated.
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
public class DockUpdate {
public static void main(String[] args) {
JButton button = new JButton();
button.addActionListener((evt) ->
System.out.println(Toolkit.getDefaultToolkit().getScreenInsets(
button.getGraphicsConfiguration())));
JFrame frame = new JFrame();
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(50, 50);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}