第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

FXML生成的JavaFX更改節(jié)點(diǎn)到另一個(gè)節(jié)點(diǎn)

FXML生成的JavaFX更改節(jié)點(diǎn)到另一個(gè)節(jié)點(diǎn)

墨色風(fēng)雨 2022-10-07 16:44:14
我有一個(gè)由 fxml 文件定義的復(fù)雜 UI。有很多 stockTextField我想更改為ControlsFX庫(kù)提供的更高級(jí)版本(可清除的文本字段)。問(wèn)題:ControlsFX 用于CustomTextField提供高級(jí)功能,但它只能被初始化,TextFields.createClearableTextField()只能從代碼中調(diào)用。我正在尋找一種TextField將通過(guò) FXMLCustomTextField初始化的 s 與從代碼初始化的 s 交換的方法,以便這些新控件將保留在 FXML 中定義的所有布局屬性。CustomTextField在 FXML 中 定義也無(wú)濟(jì)于事,因?yàn)槟J(rèn)情況下它是無(wú)用的。CustomTextField獲得了private static void setupClearButtonField(TextField inputField, ObjectProperty<Node> rightProperty)我無(wú)法調(diào)用的功能,因?yàn)樗撬接械?。ControlsFX 代碼:/** * Creates a TextField that shows a clear button inside the TextField (on * the right hand side of it) when text is entered by the user. */public static TextField createClearableTextField() {    CustomTextField inputField = new CustomTextField();    setupClearButtonField(inputField, inputField.rightProperty());    return inputField;}/** * Creates a PasswordField that shows a clear button inside the PasswordField * (on the right hand side of it) when text is entered by the user. */public static PasswordField createClearablePasswordField() {    CustomPasswordField inputField = new CustomPasswordField();    setupClearButtonField(inputField, inputField.rightProperty());    return inputField;}private static void setupClearButtonField(TextField inputField, ObjectProperty<Node> rightProperty) {    inputField.getStyleClass().add("clearable-field"); //$NON-NLS-1$    Region clearButton = new Region();    clearButton.getStyleClass().addAll("graphic"); //$NON-NLS-1$    StackPane clearButtonPane = new StackPane(clearButton);    clearButtonPane.getStyleClass().addAll("clear-button"); //$NON-NLS-1$    clearButtonPane.setOpacity(0.0);    clearButtonPane.setCursor(Cursor.DEFAULT);    clearButtonPane.setOnMouseReleased(e -> inputField.clear());    clearButtonPane.managedProperty().bind(inputField.editableProperty());    clearButtonPane.visibleProperty().bind(inputField.editableProperty());    rightProperty.set(clearButtonPane);    final FadeTransition fader = new FadeTransition(FADE_DURATION, clearButtonPane);    fader.setCycleCount(1);
查看完整描述

1 回答

?
小怪獸愛(ài)吃肉

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊

您可以fx:factory按照FXML 簡(jiǎn)介中的說(shuō)明使用。

<?xml version="1.0" encoding="UTF-8"?>


<?import javafx.scene.layout.StackPane?>

<?import org.controlsfx.control.textfield.TextFields?>


<StackPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"

           fx:controller="com.example.Controller">


    <TextFields fx:id="field" fx:factory="createClearableTextField"/>


</StackPane>

然后在控制器中使用它:


package com.example;


import javafx.fxml.FXML;

import javafx.scene.control.TextField;


public class Controller {


    @FXML private TextField field;


}

注意:如果您使用的是 IntelliJ,它會(huì)發(fā)出一條錯(cuò)誤消息:

無(wú)法將 org.controlsfx.control.textfield.TextFields 設(shè)置為字段“字段”

在 FXML 文件中,但是當(dāng)我運(yùn)行一個(gè)測(cè)試項(xiàng)目時(shí),一切正常。


查看完整回答
反對(duì) 回復(fù) 2022-10-07
  • 1 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)