Java Code Examples for javafx.scene.layout.HBox#setAlignment()

The following examples show how to use javafx.scene.layout.HBox#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: HBoxSample.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
public static Node createIconContent() {
    StackPane sp = new StackPane();
    HBox hbox = new HBox(3);
    hbox.setAlignment(Pos.CENTER);

    Rectangle rectangle = new Rectangle(70, 25, Color.LIGHTGREY);
    rectangle.setStroke(Color.BLACK);
    hbox.setPrefSize(rectangle.getWidth(), rectangle.getHeight());

    Rectangle r1 = new Rectangle(14, 14, Color.web("#1c89f4"));
    Rectangle r2 = new Rectangle(14, 14, Color.web("#349b00"));
    Rectangle r3 = new Rectangle(18, 14, Color.web("#349b00"));

    hbox.getChildren().addAll(r1, r2, r3);
    sp.getChildren().addAll(rectangle, hbox);

    return new Group(sp);
}
 
Example 2
Source File: LineIndicatorDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    CodeArea codeArea = new CodeArea();

    IntFunction<Node> numberFactory = LineNumberFactory.get(codeArea);
    IntFunction<Node> arrowFactory = new ArrowFactory(codeArea.currentParagraphProperty());
    IntFunction<Node> graphicFactory = line -> {
        HBox hbox = new HBox(
                numberFactory.apply(line),
                arrowFactory.apply(line));
        hbox.setAlignment(Pos.CENTER_LEFT);
        return hbox;
    };
    codeArea.setParagraphGraphicFactory(graphicFactory);
    codeArea.replaceText("The green arrow will only be on the line where the caret appears.\n\nTry it.");
    codeArea.moveTo(0, 0);

    primaryStage.setScene(new Scene(new StackPane(codeArea), 600, 400));
    primaryStage.show();
}
 
Example 3
Source File: DiagramSizeDialog.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Pane createButtons()
{
	Button ok = new Button(RESOURCES.getString("dialog.diagram_size.ok"));
	Button cancel = new Button(RESOURCES.getString("dialog.diagram_size.cancel"));
	ok.setOnAction(pEvent -> 
	{
		if( DiagramSizeUtils.isValid(aWidthField.getText()) && DiagramSizeUtils.isValid(aHeightField.getText()))
		{
			UserPreferences.instance().setInteger(IntegerPreference.diagramWidth, Integer.parseInt(aWidthField.getText()));
			UserPreferences.instance().setInteger(IntegerPreference.diagramHeight, Integer.parseInt(aHeightField.getText()));
			aStage.close();
		}
		else
		{
			showInvalidSizeAlert();
		}
	});
	cancel.setOnAction( pEvent -> aStage.close() );

	HBox box = new HBox(ok, cancel);
	box.setSpacing(SPACING);
	box.setAlignment(Pos.CENTER_RIGHT);
	box.setPadding(new Insets(VSPACE, 0, 0, 0));
	return box;
}
 
Example 4
Source File: App.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
private Parent buildUI() {
	fc = new FileChooser();
	fc.getExtensionFilters().clear();
	ExtensionFilter jpgFilter = new ExtensionFilter("JPG, JPEG images", "*.jpg", "*.jpeg", "*.JPG", ".JPEG");
	fc.getExtensionFilters().add(jpgFilter);
	fc.setSelectedExtensionFilter(jpgFilter);
	fc.setTitle("Select a JPG image");
	lstLabels = new ListView<>();
	lstLabels.setPrefHeight(200);
	Button btnLoad = new Button("Select an Image");
	btnLoad.setOnAction(e -> validateUrlAndLoadImg());

	HBox hbBottom = new HBox(10, btnLoad);
	hbBottom.setAlignment(Pos.CENTER);

	loadedImage = new ImageView();
	loadedImage.setFitWidth(300);
	loadedImage.setFitHeight(250);
	
	Label lblTitle = new Label("Label image using TensorFlow");
	lblTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 40));
	VBox root = new VBox(10,lblTitle, loadedImage, new Label("Results:"), lstLabels, hbBottom);
	root.setAlignment(Pos.TOP_CENTER);
	return root;
}
 
Example 5
Source File: OptionStage.java    From dm3270 with Apache License 2.0 6 votes vote down vote up
private HBox buttons ()
{
  HBox hbox = new HBox (10);
  hbox.setAlignment (Pos.CENTER);

  okButton.setDefaultButton (true);
  okButton.setPrefWidth (80);

  cancelButton.setCancelButton (true);
  cancelButton.setPrefWidth (80);

  hbox.getChildren ().addAll (cancelButton, okButton);
  hbox.setPadding (new Insets (10, 10, 10, 10));

  return hbox;
}
 
Example 6
Source File: ChoiceBoxSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    scene.setFill(Color.ALICEBLUE);
    stage.setScene(scene);
    stage.show();

    stage.setTitle("ChoiceBox Sample");
    stage.setWidth(300);
    stage.setHeight(200);

    label.setFont(Font.font("Arial", 25));
    label.setLayoutX(40);

    final String[] greetings = new String[] { "Hello", "Hola", "Привет", "你好", "こんにちは" };
    final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList("English", "Español", "Русский", "简体中文", "日本語"));

    cb.getSelectionModel().selectedIndexProperty()
            .addListener((ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> {
                label.setText(greetings[new_val.intValue()]);
            });

    cb.setTooltip(new Tooltip("Select the language"));
    cb.setValue("English");
    HBox hb = new HBox();
    hb.getChildren().addAll(cb, label);
    hb.setSpacing(30);
    hb.setAlignment(Pos.CENTER);
    hb.setPadding(new Insets(10, 0, 0, 10));

    ((Group) scene.getRoot()).getChildren().add(hb);

}
 
Example 7
Source File: Exercise_18_19.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	SierpinskiTrianglePane trianglePane = new SierpinskiTrianglePane();

	// Create to buttons
	Button btDecrease = new Button("-");
	Button btIncrease = new Button("+");

	// Create an register the handlers
	btDecrease.setOnAction(e -> {
		if (trianglePane.getOrder() > 0)
			trianglePane.setOrder(trianglePane.getOrder() - 1);
	});

	btIncrease.setOnAction(
		e -> trianglePane.setOrder(trianglePane.getOrder() + 1));
	
	// Pane to hold label, text field, and a button
	HBox hBox = new HBox(10);
	hBox.getChildren().addAll(btDecrease, btIncrease);
	hBox.setAlignment(Pos.CENTER);

	BorderPane borderPane = new BorderPane();
	borderPane.setCenter(trianglePane);
	borderPane.setBottom(hBox);

	// Create a scene and place it in the stage
	Scene scene = new Scene(borderPane, 200, 210);
	primaryStage.setTitle("Exercise_18_19"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage

	scene.widthProperty().addListener(ov -> trianglePane.paint());
	scene.heightProperty().addListener(ov -> trianglePane.paint());
}
 
Example 8
Source File: CustomNodeSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public CustomNodeSample() {        
    VBox vbox = new VBox();
    MyNode myNode = new MyNode("MyNode");
    MyNode parent = new MyNode("Parent");
    Polygon arrow = createUMLArrow();
    Label extend = new Label("<<extends>>");
    extend.setStyle("-fx-padding: 0 0 0 -1em;");
    vbox.getChildren().addAll(parent,arrow,myNode);
    vbox.setAlignment(Pos.CENTER);        
    HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);
    hbox.setPadding(new Insets(10));
    hbox.getChildren().addAll(vbox,extend);
    getChildren().addAll(hbox);
}
 
Example 9
Source File: EditAxis.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the header for the Axis Editor popup, allowing to configure axis label and unit
 *
 * @param axis The axis to be edited
 * @return pane containing label, label editor and unit editor
 */
private Node getLabelEditor(final Axis axis, final boolean isHorizontal) {
    final GridPane header = new GridPane();
    header.setAlignment(Pos.BASELINE_LEFT);
    final TextField axisLabelTextField = new TextField(axis.getName());
    axisLabelTextField.textProperty().bindBidirectional(axis.nameProperty());
    header.addRow(0, new Label(" axis label: "), axisLabelTextField);

    final TextField axisUnitTextField = new TextField(axis.getUnit());
    axisUnitTextField.setPrefWidth(50.0);
    axisUnitTextField.textProperty().bindBidirectional(axis.unitProperty());
    header.addRow(isHorizontal ? 0 : 1, new Label(" unit: "), axisUnitTextField);

    final TextField unitScaling = new TextField();
    unitScaling.setPrefWidth(80.0);
    final CheckBox autoUnitScaling = new CheckBox(" auto");
    if (axis instanceof DefaultNumericAxis) {
        autoUnitScaling.selectedProperty()
                .bindBidirectional(((DefaultNumericAxis) axis).autoUnitScalingProperty());
        unitScaling.textProperty().bindBidirectional(((DefaultNumericAxis) axis).unitScalingProperty(),
                new NumberStringConverter(new DecimalFormat("0.0####E0")));
        unitScaling.disableProperty().bind(autoUnitScaling.selectedProperty());
    } else {
        // TODO: consider adding an interface on whether
        // autoUnitScaling is editable
        autoUnitScaling.setDisable(true);
        unitScaling.setDisable(true);
    }
    final HBox unitScalingBox = new HBox(unitScaling, autoUnitScaling);
    unitScalingBox.setAlignment(Pos.BASELINE_LEFT);
    header.addRow(isHorizontal ? 0 : 2, new Label(" unit scale:"), unitScalingBox);
    return header;
}
 
Example 10
Source File: ConsoleWindow.java    From SmartModInserter with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ProcessTab(Process process) {
    this.process = process;

    hbox = new HBox();
    vbox = new VBox(log, hbox);

    Button killButton = new Button("Kill");
    killButton.setOnAction((e) -> {
        process.destroyForcibly();
    });

    hbox.setAlignment(Pos.CENTER_RIGHT);
    hbox.getChildren().add(killButton);

    VBox.setVgrow(log, Priority.ALWAYS);
    this.setContent(vbox);
    log.setWrapText(true);
    log.setFont(Font.font("Courier", 12));

    reader = new Thread(() -> {
        BufferedReader stream = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = null;
        try {
            while ((line = stream.readLine()) != null) {
                final String tmpLine = line;
                Platform.runLater(() -> {
                    String old = log.getText();
                    old += tmpLine;
                    old += "\n";
                    log.setText(old);
                    log.setScrollTop(Double.MAX_VALUE);
                });
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    });
    reader.start();
}
 
Example 11
Source File: TakeOfferView.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addSecondRow() {
    Tuple3<HBox, TextField, Label> priceAsPercentageTuple = getNonEditableValueBox();
    priceAsPercentageValueCurrencyBox = priceAsPercentageTuple.first;
    priceAsPercentageTextField = priceAsPercentageTuple.second;
    priceAsPercentageLabel = priceAsPercentageTuple.third;

    Tuple2<Label, VBox> priceAsPercentageInputBoxTuple = getTradeInputBox(priceAsPercentageValueCurrencyBox,
            Res.get("shared.distanceInPercent"));
    priceAsPercentageDescription = priceAsPercentageInputBoxTuple.first;

    getSmallIconForLabel(MaterialDesignIcon.CHART_LINE, priceAsPercentageDescription, "small-icon-label");

    priceAsPercentageInputBox = priceAsPercentageInputBoxTuple.second;

    priceAsPercentageLabel.setText("%");

    Tuple3<HBox, TextField, Label> amountValueCurrencyBoxTuple = getNonEditableValueBox();
    amountRangeTextField = amountValueCurrencyBoxTuple.second;

    minAmountValueCurrencyBox = amountValueCurrencyBoxTuple.first;
    Tuple2<Label, VBox> amountInputBoxTuple = getTradeInputBox(minAmountValueCurrencyBox,
            Res.get("takeOffer.amountPriceBox.amountRangeDescription"));

    amountRangeBox = amountInputBoxTuple.second;
    amountRangeBox.setVisible(false);

    fakeXLabel = new Label();
    fakeXIcon = getIconForLabel(MaterialDesignIcon.CLOSE, "2em", fakeXLabel);
    fakeXLabel.setVisible(false); // we just use it to get the same layout as the upper row
    fakeXLabel.getStyleClass().add("opaque-icon-character");

    HBox hBox = new HBox();
    hBox.setSpacing(5);
    hBox.setAlignment(Pos.CENTER_LEFT);
    hBox.getChildren().addAll(amountRangeBox, fakeXLabel, priceAsPercentageInputBox);

    GridPane.setRowIndex(hBox, ++gridRow);
    GridPane.setMargin(hBox, new Insets(0, 10, 10, 0));
    gridPane.getChildren().add(hBox);
}
 
Example 12
Source File: HBoxSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public HBoxSample() {
    super(400, 100);

    //Controls to be added to the HBox
    Label label = new Label("Test Label:");
    TextField tb = new TextField();
    Button button = new Button("Button...");

    //HBox with spacing = 5
    HBox hbox = new HBox(5);
    hbox.getChildren().addAll(label, tb, button);
    hbox.setAlignment(Pos.CENTER);
    getChildren().add(hbox);
}
 
Example 13
Source File: ChatPanel.java    From oim-fx with MIT License 4 votes vote down vote up
private void initComponent() {
	this.setTop(topPane);
	this.setCenter(showSplitPane);
	this.setRight(rightPane);

	//rightPane.setPrefWidth(140);
	//rightPane.setStyle("-fx-background-color:rgba(255, 255, 255, 0.5)");

	topPane.setStyle("-fx-background-color:rgba(255, 255, 255, 0.2)");
	topPane.setPrefHeight(80);
	topPane.getChildren().add(topPanel);

	WebView webView = showPanel.getWebView();
	webView.setPrefWidth(20);
	webView.setPrefHeight(50);

	showSplitPane.setTop(showBox);
	showSplitPane.setBottom(writeBox);
	showSplitPane.setStyle("-fx-background-color:rgba(255, 255, 255, 0.9)");

	showBox.getChildren().add(webView);
	VBox.setVgrow(webView, Priority.ALWAYS);

	HBox line = new HBox();
	line.setMinHeight(1);
	line.setStyle("-fx-background-color:rgba(180, 180, 180, 1);");

	middleToolBarBox.setMinHeight(25);
	middleToolBarBox.setSpacing(8);
	middleToolBarBox.setAlignment(Pos.CENTER_LEFT);

	rightFunctionBox.setPadding(new Insets(0, 5, 0, 0));
	
	HBox functionRootBox = new HBox();

	functionRootBox.setAlignment(Pos.CENTER_RIGHT);

	functionRootBox.getChildren().add(middleToolBarBox);
	functionRootBox.getChildren().add(rightFunctionBox);

	HBox.setHgrow(middleToolBarBox, Priority.ALWAYS);

	VBox writeTempBox = new VBox();

	writeTempBox.getChildren().add(line);
	writeTempBox.getChildren().add(functionRootBox);

	writeBox.getChildren().add(writeTempBox);
	writeBox.getChildren().add(writePanel);
	writeBox.getChildren().add(bottomButtonBox);

	fontBox.setMinHeight(25);
	fontBox.setSpacing(2);

	bottomButtonBox.setPadding(new Insets(0, 15, 0, 0));
	bottomButtonBox.setSpacing(5);
	bottomButtonBox.setAlignment(Pos.CENTER_RIGHT);
	bottomButtonBox.setMinHeight(40);

	closeButton.setText("关闭");
	sendButton.setText("发送");

	closeButton.setPrefSize(72, 24);
	sendButton.setPrefSize(72, 24);

	closeButton.setFocusTraversable(false);
	sendButton.setFocusTraversable(false);

	bottomButtonBox.getChildren().add(closeButton);
	bottomButtonBox.getChildren().add(sendButton);

}
 
Example 14
Source File: QuestionPane.java    From oim-fx with MIT License 4 votes vote down vote up
private void initComponent() {
	this.setStyle("-fx-background-color:#ffffff");
	upButton.setText("上一步");
	button.setText("确定");

	upButton.setPrefSize(80, 25);
	button.setPrefSize(80, 25);
	
	Label passwordLabel = new Label("新密码");
	Label confirmPasswordLabel = new Label("确认密码");

	passwordField.setPromptText("新密码");
	confirmPasswordField.setPromptText("确认密码");

	passwordLabel.setPrefSize(50, 25);
	passwordLabel.setLayoutX(10);
	passwordLabel.setLayoutY(15);
	passwordField.setPrefSize(290, 25);
	passwordField.setLayoutX(passwordLabel.getLayoutX() + passwordLabel.getPrefWidth() + 10);
	passwordField.setLayoutY(passwordLabel.getLayoutY());

	confirmPasswordLabel.setPrefSize(50, 25);
	confirmPasswordLabel.setLayoutX(10);
	confirmPasswordLabel.setLayoutY(passwordField.getLayoutY() + passwordField.getPrefHeight() + 15);
	confirmPasswordField.setPrefSize(290, 25);
	confirmPasswordField.setLayoutX(confirmPasswordLabel.getLayoutX() + confirmPasswordLabel.getPrefWidth() + 10);
	confirmPasswordField.setLayoutY(confirmPasswordLabel.getLayoutY());

	AnchorPane infoPane = new AnchorPane();

	infoPane.getChildren().add(passwordLabel);
	infoPane.getChildren().add(confirmPasswordLabel);

	infoPane.getChildren().add(passwordField);
	infoPane.getChildren().add(confirmPasswordField);
	infoPane.setPrefHeight(confirmPasswordField.getLayoutY() + 50);

	topVBox.getChildren().add(infoPane);

	scrollPane.setBackground(Background.EMPTY);
	scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
	scrollPane.setContent(box);

	HBox bottomBox = new HBox();
	bottomBox.setAlignment(Pos.CENTER);
	bottomBox.setPadding(new Insets(5, 10, 5, 10));
	bottomBox.setSpacing(10);
	bottomBox.getChildren().add(upButton);
	bottomBox.getChildren().add(button);

	over.setContentNode(overLabel);
	
	baseBorderPane.setTop(topVBox);
	baseBorderPane.setCenter(scrollPane);
	baseBorderPane.setBottom(bottomBox);
	
	this.getChildren().add(baseBorderPane);
}
 
Example 15
Source File: ChatItem.java    From oim-fx with MIT License 4 votes vote down vote up
private void initComponent() {
	getStyleClass().remove("choose-pane");
	getStyleClass().add(DEFAULT_STYLE_CLASS);
	StackPane headStackPane = new StackPane();
	headStackPane.setPadding(new Insets(8, 8, 8, 10));
	headStackPane.getChildren().add(imagePane);

	redLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1);");

	StackPane redStackPane = new StackPane();
	redStackPane.getChildren().add(redImageView);
	redStackPane.getChildren().add(redLabel);

	HBox redHBox = new HBox();
	redHBox.setAlignment(Pos.TOP_RIGHT);
	redHBox.getChildren().add(redStackPane);
	redHBox.setPadding(new Insets(5, 5, 0, 0));

	VBox redVBox = new VBox();
	redVBox.setAlignment(Pos.TOP_RIGHT);
	redVBox.getChildren().add(redHBox);

	StackPane leftStackPane = new StackPane();

	leftStackPane.getChildren().add(headStackPane);
	leftStackPane.getChildren().add(redVBox);
	// nameLabel.setFont(Font.font(15));
	//nameLabel.setStyle("-fx-text-fill:rgba(255, 255, 255,1);-fx-font-size:14px;");
	nameLabel.setStyle("-fx-font-size:14px;");
	HBox nameHBox = new HBox();
	nameHBox.getChildren().add(nameLabel);

	timeLabel.setStyle("-fx-text-fill:#666a77;");

	BorderPane nameBorderPane = new BorderPane();

	nameBorderPane.setCenter(nameHBox);
	nameBorderPane.setRight(timeLabel);

	// textLabel.setStyle("-fx-text-fill:rgba(152, 152, 152, 1);");
	textLabel.setStyle("-fx-text-fill:rgba(122, 122, 122, 1);");

	HBox textHBox = new HBox();
	textHBox.setAlignment(Pos.CENTER_LEFT);
	textHBox.getChildren().add(textLabel);

	VBox centerVBox = new VBox();
	centerVBox.setSpacing(5);
	centerVBox.setPadding(new Insets(10, 10, 0, 0));
	centerVBox.getChildren().add(nameBorderPane);
	centerVBox.getChildren().add(textHBox);

	borderPane.setLeft(leftStackPane);
	borderPane.setCenter(centerVBox);

	Image closeImageNormal = ImageBox.getImageClassPath("/classics/images/chat/item/delete_normal.png");
	closeImageView.setImage(closeImageNormal);
	closeButton.setFocusTraversable(false);
	// closeButton.setPrefWidth(16);
	// closeButton.setPrefHeight(16);
	// closeButton.setMaxHeight(16);
	closeButton.setGraphic(closeImageView);

	closeButton.getStyleClass().remove("button");
	closeButton.getStyleClass().add("chat-item-close-button");
	closeButton.setVisible(mouseEntered);

	StackPane pane = new StackPane();
	pane.getChildren().add(closeButton);
	// pane.setStyle("-fx-background-color:rgba(230, 230, 230, 1)");

	HBox box = new HBox();
	box.setAlignment(Pos.CENTER_RIGHT);
	box.getChildren().add(pane);
	box.setPadding(new Insets(0, 10, 0, 0));

	this.getChildren().add(borderPane);
	this.getChildren().add(box);
}
 
Example 16
Source File: About.java    From Game2048FX with GNU General Public License v3.0 4 votes vote down vote up
public About() {
    
    HBox title = new HBox(10);
    title.setAlignment(Pos.CENTER_LEFT);
    title.getChildren().add(new ImageView());
    title.getChildren().add(new Label("About the App"));
    
    Dialog<ButtonType> dialog = new Dialog<>();
    
    Text t00 = new Text("2048");
    t00.getStyleClass().setAll("game-label","game-lblAbout");
    Text t01 = new Text("FX");
    t01.getStyleClass().setAll("game-label","game-lblAbout2");
    Text t02 = new Text(" Game\n");
    t02.getStyleClass().setAll("game-label","game-lblAbout");
    Text t1 = new Text("JavaFX game - " + Platform.getCurrent().name() + " version\n\n");
    t1.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Text t20 = new Text("Powered by ");
    t20.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link11 = new Hyperlink();
    link11.setText("JavaFXPorts");
    link11.setOnAction(e -> browse("http://gluonhq.com/open-source/javafxports/"));
    link11.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t210 = new Text(" & ");
    t210.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link12 = new Hyperlink();
    link12.setText("Gluon Mobile");
    link12.setOnAction(e -> browse("https://gluonhq.com/products/mobile/"));
    link12.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t21 = new Text(" Projects \n\n");
    t21.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Text t23 = new Text("\u00A9 ");
    t23.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link2 = new Hyperlink();
    link2.setText("José Pereda");
    link2.setOnAction(e -> browse("https://twitter.com/JPeredaDnr"));
    link2.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t22 = new Text(", ");
    t22.getStyleClass().setAll("game-label", "game-lblAboutSub");
    Hyperlink link3 = new Hyperlink();
    link3.setText("Bruno Borges");
    link3.setOnAction(e -> browse("https://twitter.com/brunoborges"));
    Text t32 = new Text(" & ");
    t32.getStyleClass().setAll("game-label", "game-lblAboutSub");
    link3.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Hyperlink link4 = new Hyperlink();
    link4.setText("Jens Deters");
    link4.setOnAction(e -> browse("https://twitter.com/Jerady"));
    link4.getStyleClass().setAll("game-label", "game-lblAboutSub2");
    Text t24 = new Text("\n\n");
    t24.getStyleClass().setAll("game-label", "game-lblAboutSub");

    Text t31 = new Text(" Version " + Game2048.VERSION + " - " + Year.now().toString() + "\n\n");
    t31.getStyleClass().setAll("game-label", "game-lblAboutSub");

    TextFlow flow = new TextFlow();
    flow.setTextAlignment(TextAlignment.CENTER);
    flow.setPadding(new Insets(10,0,0,0));

    flow.getChildren().setAll(t00, t01, t02, t1, t20, link11, t210, link12, t21, t23, link2, t22, link3);
    flow.getChildren().addAll(t32, link4);
    flow.getChildren().addAll(t24, t31);
    
    final ImageView imageView = new ImageView();
    imageView.getStyleClass().add("about");
    
    double scale = Services.get(DisplayService.class)
            .map(display -> {
                if (display.isTablet()) {
                    flow.setTranslateY(30);
                    return 1.3;
                } else {
                    flow.setTranslateY(25);
                    return 1.0;
                }
            })
            .orElse(1.0);
    
    imageView.setFitWidth(270 * scale);
    imageView.setFitHeight(270 * scale);
    imageView.setOpacity(0.1);
    
    dialog.setContent(new StackPane(imageView, flow));
    dialog.setTitle(title);
    
    Button yes = new Button("Accept");
    yes.setOnAction(e -> {
        dialog.setResult(ButtonType.YES); 
        dialog.hide();
    });
    yes.setDefaultButton(true);
    dialog.getButtons().addAll(yes);
    javafx.application.Platform.runLater(dialog::showAndWait);
}
 
Example 17
Source File: ShtoPunetor.java    From Automekanik with GNU General Public License v3.0 4 votes vote down vote up
public ShtoPunetor(DritarjaKryesore dk, String dump){
    stage.getIcons().add(new Image(getClass().getResourceAsStream("/sample/foto/icon.png")));
    stage.setTitle("Ndrysho fjalekalimin");
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setResizable(false);
    HBox btn = new HBox(5);
    btn.setAlignment(Pos.CENTER_RIGHT);
    btn.getChildren().addAll(btnOk, btnAnulo);
    data.setValue(LocalDate.now());

    GridPane root = new GridPane();
    root.add(new Label("Emri"), 0, 0);
    root.add(user, 1, 0);
    root.add(new Label("Fjalekalimi"), 0, 1);
    root.add(pw, 1, 1);
    root.add(shfaq, 2, 1);
    root.add(lblPw, 1, 2);
    root.add(btn, 1, 4);

    shfaq.setGraphic(new ImageView(new Image("/sample/foto/eye.png")));
    shfaq.setOnMousePressed(e -> lblPw.setText(pw.getText()));
    shfaq.setOnMouseReleased(e -> lblPw.setText(""));

    user.setText(dk.log_user.getText());
    pw.setText(dk.log_pw.getText());
    user.setEditable(false);
    user.setTooltip(new Tooltip("Emri nuk mund te ndryshohet"));

    btnOk.setOnAction(e -> {
        if (pw.getText().length() > 5){
            rregullo(Integer.parseInt(dk.lblId.getText()));
        }else new Mesazhi("Info", "Fjalekalimi i shkurte", "Fjalekalimi duhet te jete mbi 5 karaktere i gjate.");
    });
    btnAnulo.setOnAction(e -> stage.close());

    pw.setOnKeyPressed(e -> {if (e.getCode().equals(KeyCode.ENTER)){
        if (pw.getText().length() > 5)
            rregullo(Integer.parseInt(dk.lblId.getText()));
        else new Mesazhi("Info", "Fjalekalimi i shkurte", "Fjalekalimi duhet te jete mbi 5 karaktere i gjate.");
    }});
    emri.setOnKeyPressed(e -> {if (e.getCode().equals(KeyCode.ENTER)){
        if (pw.getText().length() > 5)
            rregullo(Integer.parseInt(dk.lblId.getText()));
        else new Mesazhi("Info", "Fjalekalimi i shkurte", "Fjalekalimi duhet te jete mbi 5 karaktere i gjate.");
    }});

    root.setVgap(7);
    root.setHgap(5);
    root.setAlignment(Pos.CENTER);

    Scene scene = new Scene(root, 320, 210);
    scene.getStylesheets().add(getClass().getResource("/sample/style.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 18
Source File: Overlay.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void addButtons() {
    if (!hideCloseButton) {
        closeButton = new AutoTooltipButton(closeButtonText == null ? Res.get("shared.close") : closeButtonText);
        closeButton.getStyleClass().add("compact-button");
        closeButton.setOnAction(event -> doClose());
        closeButton.setMinWidth(70);
        HBox.setHgrow(closeButton, Priority.SOMETIMES);
    }

    Pane spacer = new Pane();

    if (buttonAlignment == HPos.RIGHT) {
        HBox.setHgrow(spacer, Priority.ALWAYS);
        spacer.setMaxWidth(Double.MAX_VALUE);
    }

    buttonBox = new HBox();

    GridPane.setHalignment(buttonBox, buttonAlignment);
    GridPane.setRowIndex(buttonBox, ++rowIndex);
    GridPane.setColumnSpan(buttonBox, 2);
    GridPane.setMargin(buttonBox, new Insets(buttonDistance, 0, 0, 0));
    gridPane.getChildren().add(buttonBox);

    if (actionHandlerOptional.isPresent() || actionButtonText != null) {
        actionButton = new AutoTooltipButton(actionButtonText == null ? Res.get("shared.ok") : actionButtonText);

        if (!disableActionButton)
            actionButton.setDefaultButton(true);
        else
            actionButton.setDisable(true);

        HBox.setHgrow(actionButton, Priority.SOMETIMES);

        actionButton.getStyleClass().add("action-button");
        //TODO app wide focus
        //actionButton.requestFocus();

        if (!disableActionButton) {
            actionButton.setOnAction(event -> {
                hide();
                actionHandlerOptional.ifPresent(Runnable::run);
            });
        }

        buttonBox.setSpacing(10);

        buttonBox.setAlignment(Pos.CENTER);

        if (buttonAlignment == HPos.RIGHT)
            buttonBox.getChildren().add(spacer);

        buttonBox.getChildren().addAll(actionButton);

        if (secondaryActionButtonText != null && secondaryActionHandlerOptional.isPresent()) {
            secondaryActionButton = new AutoTooltipButton(secondaryActionButtonText);
            secondaryActionButton.setOnAction(event -> {
                hide();
                secondaryActionHandlerOptional.ifPresent(Runnable::run);
            });

            buttonBox.getChildren().add(secondaryActionButton);
        }

        if (!hideCloseButton)
            buttonBox.getChildren().add(closeButton);
    } else if (!hideCloseButton) {
        closeButton.setDefaultButton(true);
        buttonBox.getChildren().addAll(spacer, closeButton);
    }
}
 
Example 19
Source File: Exercise_20_02.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class 
public void start(Stage primaryStage) {
	// Create three buttons
	Button btSort = new Button("Sort");
	Button btShuffle = new Button("Shuffle");
	Button btReverse = new Button("Reverse");

	// Create a pane to hold the textfield
	HBox paneForTextField = new HBox(10);
	paneForTextField.getChildren().addAll(
		new Label("Enter a number:"), textField);
	paneForTextField.setAlignment(Pos.CENTER);

	// Create a pane to hold buttons
	HBox paneForButtons = new HBox(5);
	paneForButtons.getChildren().addAll(
		btSort, btShuffle, btReverse);
	paneForButtons.setAlignment(Pos.CENTER);

	// Set text area editable and text wrap properties
	textArea.setEditable(false);
	textArea.setWrapText(true);

	// Create a border pane and add nodes to it
	BorderPane pane = new BorderPane();
	pane.setTop(paneForTextField);
	pane.setCenter(textArea);
	pane.setBottom(paneForButtons);


	// Create and register handles
	textField.setOnAction(e -> add()); // add and integer

	// Sort the list
	btSort.setOnAction(e -> {
		Collections.sort(list);
		displayText();
	});

	// Shuffle the list
	btShuffle.setOnAction(e -> {
		Collections.shuffle(list);
		displayText();
	});

	// Reverse the list
	btReverse.setOnAction(e -> {
		Collections.sort(list, Collections.reverseOrder());
		displayText();
	});


	// Create a Scene and place it in the stage
	Scene scene = new Scene(pane, 400, 150);
	primaryStage.setTitle("Exercise_20_02"); // Set the stage title
	primaryStage.setScene(scene); // Place a scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 20
Source File: Exercise_16_06.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Set properties for text fields
	tfTextField.setText("JavaFX");
	tfTextField.setAlignment(Pos.BOTTOM_CENTER);
	tfColumnSize.setAlignment(Pos.BOTTOM_RIGHT);
	tfColumnSize.setPrefColumnCount(3);
	tfTextField.setPrefColumnCount(12);
	tfColumnSize.setText("12");

	// Create three radio buttions
	RadioButton rbLeft = new RadioButton("Left");
	RadioButton rbCenter = new RadioButton("Center");
	RadioButton rbRight = new RadioButton("Right");
	rbCenter.setSelected(true);

	// Create a toggle group
	ToggleGroup group = new ToggleGroup();
	rbLeft.setToggleGroup(group);
	rbCenter.setToggleGroup(group);
	rbRight.setToggleGroup(group);
	
	// Create four hbox
	HBox paneForRadioButtons = new HBox(5);
	paneForRadioButtons.getChildren().addAll(rbLeft, rbCenter, rbRight);
	paneForRadioButtons.setAlignment(Pos.BOTTOM_LEFT);

	HBox paneForColumnSize = new HBox(5);
	paneForColumnSize.getChildren().addAll(
		new Label("Colum Size"), tfColumnSize);

	HBox paneForTextField = new HBox(5);
	paneForTextField.setAlignment(Pos.CENTER);
	paneForTextField.getChildren().addAll(
		new Label("Text Field"), tfTextField);

	HBox hbox = new HBox(10);
	hbox.getChildren().addAll(paneForRadioButtons, paneForColumnSize);

	// Create a vBox and place nodes in it
	VBox pane = new VBox(10);
	pane.setPadding(new Insets(5, 5, 5, 5));
	pane.getChildren().addAll(paneForTextField, hbox);

	// Create and register the handlers 
	rbLeft.setOnAction(e -> {
		if (rbLeft.isSelected()) {
			tfTextField.setAlignment(Pos.BOTTOM_LEFT);
		}
	});

	rbCenter.setOnAction(e -> {
		if (rbCenter.isSelected()) {
			tfTextField.setAlignment(Pos.BOTTOM_CENTER);
		}
	});

	rbRight.setOnAction(e -> {
		if (rbRight.isSelected()) {
			tfTextField.setAlignment(Pos.BOTTOM_RIGHT);
		}
	});

	tfColumnSize.setOnKeyPressed(e -> {
		if (e.getCode() == KeyCode.ENTER) {
			tfTextField.setPrefColumnCount(Integer.parseInt(
				tfColumnSize.getText()));
		}
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane);
	primaryStage.setTitle("Exercise_16_06"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}