AnchorPane is a powerful tool for fine-tuning the resize process. It allows us to precisely attach nodes to the four sides of the window.
Imagine we are creating a browser that consists of the following components:
- An address bar
- Navigation buttons
- A status bar
- A web view:
If the browser is being resized, we want the following adaptive behavior:
- The address bar stays on top and changes size only in the horizontal direction
- Same for the status bar, but in the bottom
- The web view is the most important part and should take as much space as possible
- Buttons shouldn't resize at all, but we want them to stay at the same location
To achieve that, we put them all into AnchorPane and attach them to its borders correspondingly:
One way is to do it through an API, as in the following example:
AnchorPane root = new AnchorPane();
TextField...