小编Vik*_*ngh的帖子

如何在Javafx中对齐对话框窗格的确定按钮?

我想对齐,即将ENTERPENTER设置为DialogPane的OK按钮。我已经尝试了以下代码,但无法正常工作。

Dialog dialog = new Dialog();
DialogPane dialogPane = dialog.getDialogPane();
dialogPane.setStyle("-fx-background-color: #fff;");

        // Set the button types.
ButtonType okButtonType = new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
dialog.getDialogPane().getButtonTypes().addAll(okButtonType, cancelButtonType);
dialogPane.lookupButton(cancelButtonType).setVisible(false);

        // Testing
Button okButton = (Button) dialog.getDialogPane().lookupButton(okButtonType);
okButton.setAlignment(Pos.CENTER);
        // End Testing

dialog.showAndWait();
Run Code Online (Sandbox Code Playgroud)

dialog javafx javafx-2 javafx-8

6
推荐指数
1
解决办法
4499
查看次数

在Javafx中输入关键事件不能正常工作?

我已经尝试了下面的代码,它适用于鼠标事件,但当我使用键事件,即任何按钮上的ENTER键,而不是显示结果.

Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle(null);
alert.setHeaderText(null);
alert.setGraphic(null);
alert.setContentText("Choose your option.");

ButtonType buttonTypeOne = new ButtonType("One");
ButtonType buttonTypeTwo = new ButtonType("Two");
ButtonType buttonTypeThree = new ButtonType("Three");

alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeThree);

Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne) {
     System.out.println("One");
} else if (result.get() == buttonTypeTwo) {
     System.out.println("Two");
} else if (result.get() == buttonTypeThree) {
     System.out.println("Three");
}
Run Code Online (Sandbox Code Playgroud)

javafx javafx-2 javafx-8

2
推荐指数
1
解决办法
3058
查看次数

如何使用Javafx获取TableView中多个选定行的值?

我已尝试使用以下代码进行 TableView 多重选择。我只想要 ArrayList 中所选行的所有 ID。但每当我选择行而不是显示 ID 时,就会显示完整的行值。

package tabletest;

import java.util.ArrayList;
import java.util.ListIterator;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 *
 * @author vikassingh
 */
public class TableTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        TableView<ObservableList<String>> tableLocal = new TableView<>();
        tableLocal.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        TableColumn<ObservableList<String>, String> idCol = new TableColumn<>("ID");
        TableColumn<ObservableList<String>, String> nameCol = new TableColumn<>("Customer Name");

        tableLocal.getColumns().addAll(nameCol);

        //idCol
        idCol.setCellValueFactory(cellData -> { …
Run Code Online (Sandbox Code Playgroud)

javafx javafx-2 javafx-8

2
推荐指数
1
解决办法
5564
查看次数

标签 统计

javafx ×3

javafx-2 ×3

javafx-8 ×3

dialog ×1