Java Code Examples for javafx.scene.control.Button#setAlignment()

The following examples show how to use javafx.scene.control.Button#setAlignment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusPanel.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new status panel.
 * <p/>
 * @param group the group this panel is part of.
 * @param labelText the text to put on the label on this panel.
 * @param index the index of this panel on the group.
 */
StatusPanel(StatusPanelGroup group, String labelText, int index) {
    setAlignment(Pos.CENTER);
    setSpacing(5);
    this.group = group;
    this.index = index;
    label = new Label(labelText);
    label.setAlignment(Pos.CENTER);
    label.setMaxHeight(Double.MAX_VALUE);
    HBox.setMargin(label, new Insets(5));
    progressBar = new ProgressBar();
    progressBar.setMaxWidth(Double.MAX_VALUE); //Allow progress bar to fill space.
    HBox.setHgrow(progressBar, Priority.ALWAYS);
    cancelButton = new Button("", new ImageView(new Image("file:icons/cross.png", 13, 13, false, true)));
    Utils.setToolbarButtonStyle(cancelButton);
    cancelButton.setAlignment(Pos.CENTER);
    getChildren().add(label);
    getChildren().add(progressBar);
    getChildren().add(cancelButton);
}
 
Example 2
Source File: MainNode.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
public void setToolbarButton(EventHandler<ActionEvent> backevent, Node graphic, String text) {
    
    Label l = new Label();
    l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    l.setAlignment(Pos.CENTER);
    l.setGraphic(graphic);
    l.setPrefSize(45.0, 40.0);             
    
    backbutton = new Button(text, l);     
    backbutton.setAlignment(Pos.BASELINE_LEFT);
    backbutton.setMaxWidth(Double.MAX_VALUE);
    backbutton.setFocusTraversable(false);
    backbutton.setMnemonicParsing(false);
    backbutton.getStyleClass().add("menubutton");
    backbutton.setOnAction(backevent);
    backbutton.setVisible(backevent != null);
}
 
Example 3
Source File: ModalCancellableStage.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public ModalCancellableStage(String displayText) {
    initModality(Modality.APPLICATION_MODAL);
    initStyle(StageStyle.UNDECORATED);
    setOnShowing((event) -> {
        centerOnScreen();
        cancel = false;
    });
    StackPane root = new StackPane();
    VBox items = new VBox(10);
    Label label = new Label(displayText);
    label.setAlignment(Pos.CENTER);
    items.getChildren().add(label);
    StackPane barPane = new StackPane();
    ProgressBar bar = new ProgressBar();
    bar.setMaxWidth(Double.MAX_VALUE);
    bar.prefWidthProperty().bind(widthProperty().subtract(50));
    StackPane.setAlignment(bar, Pos.CENTER);
    barPane.getChildren().add(bar);
    barPane.setAlignment(Pos.CENTER);
    items.getChildren().add(barPane);
    StackPane buttonPane = new StackPane();
    Button cancelButton = new Button(LabelGrabber.INSTANCE.getLabel("cancel.text"));
    StackPane.setAlignment(buttonPane, Pos.CENTER);
    buttonPane.setAlignment(Pos.CENTER);
    buttonPane.getChildren().add(cancelButton);
    cancelButton.setAlignment(Pos.CENTER);
    cancelButton.setOnAction((event) -> {
        cancel = true;
        hide();
        cancellable.cancelOp();
    });
    items.getChildren().add(buttonPane);
    StackPane.setMargin(items, new Insets(10));
    root.getChildren().add(items);
    Scene scene = new Scene(root);
    if (QueleaProperties.get().getUseDarkTheme()) {
        scene.getStylesheets().add("org/modena_dark.css");
    }
    setScene(scene);
}
 
Example 4
Source File: BigButtonDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Alpha Base" + System.lineSeparator() + "Population : 8");
    btn.setGraphic(new Rectangle(30,30, Color.RED));
    btn.setMinHeight(200);
    btn.setMinWidth(250);
    //btn.setStyle("-fx-alignment: LEFT;");
    btn.setAlignment(Pos.BASELINE_LEFT);

    StackPane root = new StackPane();
    root.getChildren().add(btn);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}
 
Example 5
Source File: DataCollectionUI.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
final public void collectDataUI(){
    GridPane gridLEFT = new GridPane();
    Label queryLabel = new Label("Query");
    UIUtils.setSize(queryLabel,Main.columnWidthLEFT/2, 24);
    TextField queryField = new TextField();
    queryField.setPromptText("formatted query");
    UIUtils.setSize(queryField,Main.columnWidthLEFT/2, 24);
    Label durationLabel = new Label("Duration");
    UIUtils.setSize(durationLabel,Main.columnWidthLEFT/2, 24);
    TextField durationField = new TextField();
    durationField.setPromptText("duration in days (e.g. 2)");
    UIUtils.setSize(durationField,Main.columnWidthLEFT/2, 24);
    Label datasetIDLabel = new Label("Dataset ID");
    UIUtils.setSize(datasetIDLabel,Main.columnWidthLEFT/2, 24);
    TextField datasetIDField = new TextField();
    datasetIDField.setPromptText("unique identifier");
    UIUtils.setSize(datasetIDField,Main.columnWidthLEFT/2, 24);
    
    gridLEFT.add(queryLabel,0,0);
    gridLEFT.add(queryField,1,0);
    gridLEFT.add(new Rectangle(0,3),0,1);
    gridLEFT.add(durationLabel,0,2);
    gridLEFT.add(durationField,1,2);
    gridLEFT.add(new Rectangle(0,3),0,3);
    gridLEFT.add(datasetIDLabel,0,4);
    gridLEFT.add(datasetIDField,1,4);
    
    Button button = new Button("Collect");
    UIUtils.setSize(button,Main.columnWidthRIGHT, 24);
    button.setAlignment(Pos.CENTER);
    VBox buttonBox = new VBox();
    buttonBox.setAlignment(Pos.CENTER);
    buttonBox.getChildren().add(button);
    
    HBox collectDataBOTH = new HBox(5);
    collectDataBOTH.getChildren().addAll(gridLEFT,buttonBox);
    grid.add(collectDataBOTH,0,8);
}
 
Example 6
Source File: LayersViewPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
public LayersViewPane(final LayersViewController controller) {

        // create controller
        this.controller = controller;

        // create layer headings
        final Label layerIdHeadingText = new Label("Layer\nID");
        final Label visibilityHeadingText = new Label("Visibility");
        final Label queryHeadingText = new Label("Query");
        final Label descriptionHeadingText = new Label("Description");

        // create gridpane and alignments
        layersGridPane = new GridPane();
        layersGridPane.setHgap(5);
        layersGridPane.setVgap(5);
        layersGridPane.setPadding(new Insets(0, 10, 10, 10));
        layersGridPane.addRow(0, layerIdHeadingText, visibilityHeadingText,
                queryHeadingText, descriptionHeadingText);

        // set heading alignments
        GridPane.setMargin(layerIdHeadingText, new Insets(15, 0, 0, 0));
        layerIdHeadingText.setTextAlignment(TextAlignment.CENTER);
        layerIdHeadingText.setMinWidth(40);
        layerIdHeadingText.setMinHeight(25);
        layerIdHeadingText.setPrefWidth(30);
        visibilityHeadingText.setPrefWidth(55);
        visibilityHeadingText.setMinWidth(50);
        queryHeadingText.setPrefWidth(10000);
        queryHeadingText.setMinWidth(80);
        descriptionHeadingText.setPrefWidth(10000);
        descriptionHeadingText.setMinWidth(80);

        // instantiate list of layers
        layers = new ArrayList<>();

        // set default layers
        setDefaultLayers();

        // create options
        final Button addButton = new Button("Add New Layer");
        addButton.setAlignment(Pos.CENTER_RIGHT);
        addButton.setOnAction(event -> {
            if (layersGridPane.getRowCount() <= 32) {
                createLayer(layers.size() + 1, false, "", "");
                controller.writeState();
            } else {
                final NotifyDescriptor nd = new NotifyDescriptor.Message(
                        "You cannot have more than 32 layers", NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(nd);
            }
            event.consume();
        });
        HBox.setHgrow(addButton, Priority.ALWAYS);

        final Button deselectAllButton = new Button("Deselect All Layers");
        deselectAllButton.setAlignment(Pos.CENTER_RIGHT);
        deselectAllButton.setOnAction(event -> {
            for (final LayerDescription layer : layers) {
                layer.setCurrentLayerVisibility(false);
            }
            if (this.layers.isEmpty()) {
                setDefaultLayers();
            } else {
                setLayers(List.copyOf(layers));
            }
            controller.submit();
            controller.execute();

            event.consume();
        });
        HBox.setHgrow(deselectAllButton, Priority.ALWAYS);

        this.options = new HBox(5, addButton, deselectAllButton);
        options.setAlignment(Pos.TOP_LEFT);
        options.setPadding(new Insets(0, 0, 0, 10));

        // add layers grid and options to pane
        this.layersViewPane = new VBox(5, layersGridPane, options);

        // create layout bindings
        layersViewPane.prefWidthProperty().bind(this.widthProperty());
        options.prefWidthProperty().bind(layersViewPane.widthProperty());

        this.setCenter(layersViewPane);
        controller.writeState();
    }
 
Example 7
Source File: SortManager.java    From PDF4Teachers with Apache License 2.0 4 votes vote down vote up
public void setup(GridPane parent, String selectedButtonName, String... buttonsName){

        int row = 0;
        for(String buttonName : buttonsName){

            if(buttonName.equals("\n")){
                row++; continue;
            }

            Button button = new Button(buttonName);
            button.setGraphic(Builders.buildImage(getClass().getResource("/img/Sort/up.png")+"", 0, 0));
            button.setAlignment(Pos.CENTER_LEFT);
            button.setMaxWidth(Double.MAX_VALUE);
            GridPane.setHgrow(button, Priority.ALWAYS);
            BooleanProperty order = new SimpleBooleanProperty(true);
            buttons.put(button, order);
            parent.addRow(row, button);

            if(selectedButtonName.equals(buttonName)){
                selectedButton.set(button);
                button.setStyle("-fx-background-color: " + selectedColor + ";");
            }else button.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");

            // Image de l'ordre
            order.addListener(new ChangeListener<>() {
                @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean lastOrder, Boolean newOrder) {
                    button.setGraphic(Builders.buildImage(getClass().getResource(newOrder ? "/img/Sort/up.png" : "/img/Sort/down.png") + "", 0, 0));
                }
            });

            // Change selectedButton lors du clic ET update l'ordre
            button.setOnAction(actionEvent -> {
                if(selectedButton.get() == button){
                    order.set(!order.get());
                    updateSort.call(button.getText(), order.get());
                }else selectedButton.set(button);
            });
        }
        if(selectedButton.get() == null){
            selectedButton.set(buttons.keySet().iterator().next());
            buttons.keySet().iterator().next().setStyle("-fx-background-color: " + selectedColor);
        }

        // Couleurs des boutons
        selectedButton.addListener((observableValue, lastSelected, newSelected) -> {
            lastSelected.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");
            newSelected.setStyle("-fx-background-color: " + selectedColor + ";");
            updateSort.call(newSelected.getText(), buttons.get(newSelected).get());
        });
    }
 
Example 8
Source File: MainNode.java    From helloiot with GNU General Public License v3.0 4 votes vote down vote up
public void construct(List<UnitPage> appunitpages) {
    
    appunitpage.subscribeStatus(messagePageHandler);
    appbeeper.subscribeStatus(beeper.getMessageHandler());
    appbuzzer.subscribeStatus(buzzer.getMessageHandler());
    systime.subscribeStatus(timeindicator.getMessageHandler());

    // Add configured unitpages.
    for (UnitPage up : appunitpages) {
        this.addUnitPage(up);
    }

    //Init unit nodes
    for (Unit u : app.getUnits()) {
        Node n = u.getNode();
        if (n != null) {
            UnitPage unitpage = buildUnitPage(UnitPage.getPage(n));
            unitpage.addUnitNode(n);
        }
    }

    // Build listpages based on unitpages
    List<UnitPage> sortedunitpages = new ArrayList<>();
    sortedunitpages.addAll(unitpages.values());
    Collections.sort(sortedunitpages);
    firstmenupage = null;
    for (UnitPage value : sortedunitpages) {
        value.buildNode();
        if (!value.isSystem() && !value.isEmpty() && (value.getName() == null || !value.getName().startsWith("."))) {
            Label l = new Label();
            l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            l.setAlignment(Pos.CENTER);
            l.setGraphic(value.getGraphic());
            l.setPrefSize(45.0, 40.0);                
            Button buttonmenu = new Button(value.getText(), l);
            buttonmenu.getStyleClass().add("menubutton");
            buttonmenu.setAlignment(Pos.BASELINE_LEFT);
            buttonmenu.setMaxWidth(Double.MAX_VALUE);
            buttonmenu.setFocusTraversable(false);
            buttonmenu.setMnemonicParsing(false);
            buttonmenu.setOnAction(e -> {
                appunitpage.sendStatus(value.getName());              
            });
            menupages.getChildren().add(buttonmenu); // Last button is disconnect button
            if (firstmenupage == null) {
                firstmenupage = value.getName();
            }
        }
    }
    
    // Add backbutton
    if (backbutton != null && backbutton.isVisible()) {
        menupages.getChildren().add(new Separator(Orientation.HORIZONTAL));
        menupages.getChildren().add(backbutton);
    }
    
    gotoPage("start");

    // Remove menubutton if 0 or 1 visible page.
    menubutton.setVisible(!menupages.getChildren().isEmpty());
}