Skip to content

Instantly share code, notes, and snippets.

@setaniel
Last active August 25, 2020 08:20
Show Gist options
  • Save setaniel/f394ff8f6072d5eac00a220a5126b8f9 to your computer and use it in GitHub Desktop.
Save setaniel/f394ff8f6072d5eac00a220a5126b8f9 to your computer and use it in GitHub Desktop.
JavaFX. Auto-resizing HTML Editor panel node in parent node (авторазмер htmleditor панели)
public class ResizableHTMLEditor extends Application {
private HTMLEditor htmlEditor = new HTMLEditor();
private static AnchorPane anchorPane = new AnchorPane();
private Scene scene = new Scene(anchorPane, 420, 565, Color.TRANSPARENT);
@Override
public void start(Stage stage) throws Exception {
htmlEditor.setPrefWidth(360);
//add listener for change size a html editor, if a window size is changed
ChangeListener<Number> stageSizeListener = (observable, oldValue, newValue) ->
{
//___________TOP NODE
Node topNode = htmlEditor.lookup(".top-toolbar");
if (topNode instanceof ToolBar) {
ToolBar toolBarBar = (ToolBar) topNode;
toolBarBar.setPrefWidth(anchorPane.getWidth());
}
//___________BOTTOM NODE
Node bottomNode = htmlEditor.lookup(".bottom-toolbar");
if (bottomNode instanceof ToolBar) {
ToolBar bottomBar = (ToolBar) bottomNode;
bottomBar.setPrefWidth(anchorPane.getWidth());
}
//----------------
};
stage.widthProperty().addListener(stageSizeListener);
stage.heightProperty().addListener(stageSizeListener);
// setting indentation so that buttons do not clip, removing blue focus borders
AnchorPane.setLeftAnchor(htmlEditor, 10.0);
AnchorPane.setRightAnchor(htmlEditor, 10.0);
anchorPane.getChildren().addAll(htmlEditor);
anchorPane.setStyle("-fx-focus-color: transparent; -fx-control-inner-background: transparent ; -fx-faint-focus-color: transparent; -fx-control-inner-background: transparent ;");
anchorPane.setId("textEditor");
//run scene
stage.setScene(scene);
stage.show();
stage.setTitle("ResizableHTMLEditor");
}
public static AnchorPane textEditor(){
return anchorPane;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment