UI layouts are always a hassle.
My implementation in Java with a few extensions: https://github.com/palexdev/rectcut-java
My implementation in Java with a few extensions: https://github.com/palexdev/rectcut-java