【发布时间】:2019-05-16 16:22:31
【问题描述】:
我有这个代码:
public static void main(String[] ar){
launch(ar);
}
@Override
public void start(Stage primaryStage){
TitledPane titledPane = new TitledPane("", null);
titledPane.setCollapsible(false);
titledPane.setContent(new javafx.scene.control.TextArea("George"));
Platform.runLater(() -> {
titledPane.lookup(".title").setStyle("-fx-background-color: rgba(255, 255, 255, 1);" +
"-fx-border-style: solid;" +
"-fx-border-color: rgba(0, 0, 0, 1);" +
"-fx-border-width: 1px;");
titledPane.lookup(".content").setStyle("-fx-background-color: rgba(255, 255, 255, 1);" +
"-fx-border-style: solid;" +
"-fx-border-color: rgba(0, 0, 0, 1);" +
"-fx-border-width: 1px;");
});
HBox hBox = new HBox();
hBox.setAlignment(Pos.CENTER);
Text textTitle = new Text("CONSOLE");
Button buttonClear = new Button("CLEAR");
HBox.setMargin(textTitle, new Insets(0, 10, 0, 0));
hBox.getChildren().addAll(textTitle, buttonClear);
titledPane.setGraphic(hBox);
primaryStage.setScene(new Scene(titledPane));
primaryStage.show();
}
如果我将鼠标放在红线区域,它会触发按钮清除的鼠标悬停效果。
如果我没有鼠标,如何停止触发按钮的鼠标悬停效果?
【问题讨论】:
-
您发布的代码的第一行中的
content是什么? -
@Abra 这是一个文本区域
-
那么我可以用
new javafx.scene.control.TextArea("George")替换它吗? -
@Abra 实际上没有。我更新了我的代码。
-
我相信 TitledPanes 使它们的整个顶部成为交互式折叠按钮。为什么不创建一个 HBox 来保存您的标签和按钮,并将其放在 BorderPane 的顶部区域?