Reputation: 384
got this
package net.makerimages.starling.src.window;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import net.makerimages.starling.src.Main;
/**
* Created with IntelliJ IDEA.
* User: Kodukas
* Date: 29.11.13
* Time: 23:53
* To change this template use File | Settings | File Templates.
*/
public class TopBar extends HBox
{
public Button closeButton;
public Button minMaxButton;
public Label titleLabel;
public TopBar()
{
titleLabel=new Label("Starling browser");
closeButton=new Button("X");
closeButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
Platform.exit();
}
});
closeButton.setStyle("-fx-opacity: 0.9;");
minMaxButton=new Button("| |");
minMaxButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
if(Main.stg.isFullScreen()==false)
{
Main.stg.setFullScreen(true);
minMaxButton.setText("||");
}
else if(Main.stg.isFullScreen()==true)
{
Main.stg.setFullScreen(false);
minMaxButton.setText("| |");
Main.browser.setMaxHeight(Main.browser.getHeight()-20);
}
}
});
this.getChildren().addAll(closeButton,minMaxButton);
this.getChildren().add(titleLabel);
setMargin(titleLabel,new Insets(0,10,0,0));
}
}
What I would like to have is the buttons on the right and the label in the centre, however anything I`ve tried for that has not worked.(this is used as a toolbar in a borderPane) Ive tried literally everything I know of
Upvotes: 0
Views: 2745
Reputation: 1954
I would suggest use a GridPane
and add the elements to the row and column they need them to be in.
Upvotes: 0
Reputation: 15742
Use a StackPane
as the base container for your toolbar. Add a Label
and a HBox
to the StackPane. The Label will automatically be aligned to the center. Add the buttons to the HBox; on the HBox set the alignment property to TOP_RIGHT
. Set padding, spacing etc. as needed.
It's very helpful to use SceneBuilder for experimenting with layouts like this.
Upvotes: 2