java focus workaround

workaround for #227
Closes #227
Closes #289

@tych0: rearranged some code