--- old/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java 2018-04-12 16:16:34.197558000 +0100 +++ new/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java 2018-04-12 16:16:33.712353400 +0100 @@ -1097,6 +1097,7 @@ /////////////////////////////////////////////////////////////////////////// private volatile Component compOnTouchDownEvent; private volatile Component compOnMousePressedEvent; + private volatile Component compTouchKbrdWasShownFor; @Override public void showOrHideTouchKeyboard(Component comp, AWTEvent e) { @@ -1125,18 +1126,26 @@ .isCausedByTouchEvent(me)) { if (compOnTouchDownEvent == comp) { showTouchKeyboard(true); + compTouchKbrdWasShownFor = comp; } compOnTouchDownEvent = null; } else { if (compOnMousePressedEvent == comp) { showTouchKeyboard(false); + compTouchKbrdWasShownFor = comp; } compOnMousePressedEvent = null; } } } else if (e instanceof FocusEvent) { - if (e.getID() == FocusEvent.FOCUS_LOST) { - hideTouchKeyboard(); + FocusEvent fe = (FocusEvent)e; + if (fe.getID() == FocusEvent.FOCUS_LOST) { + // Do not hide the touch keyboard, if it has just been shown for + // a component which gains focus. + if (fe.getOppositeComponent() != compTouchKbrdWasShownFor) { + hideTouchKeyboard(); + } + compTouchKbrdWasShownFor = null; } } }