where is the underscore in my CheckBox?

2019-04-27 09:05发布

问题:

The shortest possible program to show my problem:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class TestCheckBox extends Application  {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage stage) {
        Scene scene = new Scene(new StackPane());
        final VBox vbox = new VBox();
        vbox.getChildren().addAll(new Label("ABC_DEF"), new CheckBox("ABC_DEF"));
        ((StackPane) scene.getRoot()).getChildren().add(vbox);
        stage.setScene(scene);
        stage.show();
    }
}

leads to:

In SceneBuilder by comparison it´s displayed normally, but not in my application. I am running Java 1.8.0-b129

Any hint?

回答1:

You probably want to setMnemonicParsing to false on the CheckBox.

MnemonicParsing property to enable/disable text parsing. If this is set to true, then the Label text will be parsed to see if it contains the mnemonic parsing character '_'. When a mnemonic is detected the key combination will be determined based on the succeeding character, and the mnemonic added.

The default value for Labeled is false, but it is enabled by default on some Controls.