I want to add a title bar to my undecorated JavaFX Window and I display the default icons(close, minimize) to be displayed there.
My Stage contains A Border Pane with an HBox inside
BorderPane root = new BorderPane();
HBox title = new HBox();
Button close = new Button();
Button min = new Button();
title.getChildren().addAll(close, min);
root.setTop(title);
root.setBottom(grid);
Related
How to make such a settings panel so that you can see the scene with 3d figures as in the picture?
my scene is under the panel.
I create a BorderPane,
And she completely closes the scene.
My code is in the second picture, but I don’t know how to make the scene visible
RadioButton rdoEasy = new RadioButton("Easy");
RadioButton rdoMedium = new RadioButton("Medium");
RadioButton rdoHard = new RadioButton("Hard");
var groupDifficulty = new ToggleGroup();
groupDifficulty.getToggles().addAll(
rdoEasy,
rdoMedium,
rdoHard
);
ToolBar toolBar = new ToolBar();
toolBar.setOrientation(Orientation.VERTICAL);
toolBar.getItems().addAll(
new Separator(),
rdoEasy,
rdoMedium,
rdoHard,
new Separator()
);
BorderPane borderPane = new BorderPane();
borderPane.setLeft(toolBar);
borderPane.setCenter(group);
borderPane.getCenter();
Scene scene = new Scene(borderPane, orgSceneX, orgSceneY,true,SceneAntialiasing.BALANCED);
I'm working on a school project in Java FX, I'd like to add an icon next to my primarystage title and center the title, just like the one in the picture. I have looked around in the javadoc for Stage but i can only find the setTitle() method. Here is a link to what i'd like to do :
You can set your stage to undecorated, set your scene root to a border pane and create your own custom top bar.
BorderPane root = new BorderPane();
root.setTop(new Pane(bb, label));
Scene scene = new Scene(root, 400, 400);
ButtonBar topBar = new ButtonBar(… insert buttons in here....);
// eg: Button b = new Button("X); b.setOnAction(e->{stage.close();});
root.setTop(topBar);
stage.initStyle(StageStyle.UNDECORATED);
Does anyone know how to programmatically collapse a TitledPane in JavaFX? I know the methods setExpanded and setCollapsible are available but it only enables the property. I want to collapse the pane without any mouse interaction.
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
TitledPane titledPane = new TitledPane();
titledPane.setAnimated(true);
titledPane.setText("This is a test");
titledPane.setContent(btn);
titledPane.setExpanded(true);
Accordion accordion = new Accordion();
accordion.getPanes().add(titledPane);
Button show = new Button("Expand");
show.setOnAction((ActionEvent event) -> {
accordion.setExpandedPane(titledPane); // Expanded Pane works!
});
Button hide = new Button("Collapse");
hide.setOnAction((ActionEvent event) -> {
//???
});
HBox layout = new HBox(10);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
layout.getChildren().addAll(show, hide, accordion);
Scene scene = new Scene(layout, 320, 240);
scene.setFill(Color.GHOSTWHITE);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
Here is the result I am looking for
Since only one TitledPane in the same Accordion can be expanded at any time, the Accordion (to some extent) manages the expanded state of any TitledPanes it contains.
You can do
accordion.setExpandedPane(titledPane);
to get the accordion to expand titledPane.
Calling titledPane.setExpanded(true); also works, but only if you invoke this after the window has been shown (for reasons I don't fully understand).
Following is my code for showing a dialog when some error or warning occurs,
but I am unable to align the text and button. both things cover each other.
//INITIALIZING SCENE FOR dialogStage
StackPane dialogStackPane = new StackPane();
dialogStackPane.setAlignment(Pos.CENTER);
dialogStackPane.setLayoutX(0);
dialogStackPane.setLayoutY(0);
dialogStackPane.setPrefWidth(250.0);
dialogStackPane.setPrefHeight(150.0);
// dialogStage height and width
dialogStage.setHeight(150.0);
dialogStage.setWidth(250.0);
//Scene for dialogStage
sceneDialog = new Scene(dialogStackPane, 150.0, 250.0);
sceneDialog.getStylesheets().add("/styles/Login.css");
// Dialog box button
btnDialog = new Button("close");
btnDialog.setMinSize(10.0, 20.0);
ObservableList ol = dialogStackPane.getChildren();
ol.add(textWarning);
ol.add(btnDialog);
textWarning.setX(0);
textWarning.setY(0);
btnDialog.setLayoutX(0);
btnDialog.setLayoutY(0);
// SETTING THE MODALITY OF THE DIALOG BOX
dialogStage.initModality(Modality.APPLICATION_MODAL);
dialogStage.setTitle("Warning");
dialogStage.setScene(sceneDialog);
// Setting event listener on warning dialogStage button b
btnDialog.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() {
// This handles the Mouse event of the dialog box button.
#Override
public void handle(MouseEvent t) {
if (t.getEventType() == MouseEvent.MOUSE_CLICKED) {
dialogStage.close();
}
}
});
textWarning.setLayoutX(20);
textWarning.setLayoutY(200);
// textWarning.setTextOrigin(VPos.TOP);
// textWarning.setTextAlignment(TextAlignment.LEFT);
// Sets the warning box
dialogStage.setResizable(false);
any help would be appreciated.
Use an AnchorPane instead of a StackPane. Then you can position any node by static methods in AnchorPane class.
AnchorPane pane = new AnchorPane();
...
AnchorPane.setLeftAnchor(textWarning, 50.0);
AnchorPane.setLeftAnchor(btnDialog, 50.0);
AnchorPane.setTopAnchor(textWarning, 20.0);
AnchorPane.setTopAnchor(btnDialog, 50.0);
...
pane.getChildren().addAll(textWarning, btnDialog);
...
sceneDialog = new Scene(pane, 150.0, 250.0);
...
I am trying to add a ToolBar control, containing 2 Buttons and a TextField in my scene graph.
I want that the TextField control gets automatically resized and acquire all the space available into toolbar. So, I used the HBox layout control to add the buttons and textfield.
I did as followed:
ToolBar tb = new ToolBar();
HBox hbox = new HBox(8);
TextField tf = new TextField();
HBox.setHgrow(tf, Priority.ALWAYS);
hbox.getChildren().add(new Button("<-"));
hbox.getChildren().add(new Button("->"));
hbox.getChildren().add(tf);
tb.getItems().add(hbox);
But its not working. Where am I going wrong? Please help.
You can try next:
ToolBar tb = new ToolBar();
TextField tf = new TextField();
HBox hbox = new HBox(8);
hbox.prefWidthProperty().bind(tb.widthProperty().subtract(20));
HBox.setHgrow(tf, Priority.ALWAYS);
hbox.getChildren().add(new Button("<-"));
hbox.getChildren().add(new Button("->"));
hbox.getChildren().add(tf);
tb.getItems().add(hbox);