Автозаполнение ColtrolsFx не отображаетсяJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Автозаполнение ColtrolsFx не отображается

Сообщение Anonymous »

Я пытаюсь связать автоматическое завершение текстового поля с помощью библиотеки controlfx. Проблема в том, что каким-то образом в упакованной версии приложения оно не отображается, а в версии gradle-run или tar/zip (без связанного jre) — да.
В области класса:

Код: Выделить всё

private AutoCompletionBinding softwareAutoCompletion;
private AutoCompletionBinding usernameAutoCompletion;
В области void инициализации (расположение URL-адреса, ресурсы ResourceBundle):

Код: Выделить всё

Platform.runLater(() -> {
softwareAutoCompletion = TextFields.bindAutoCompletion(editorSoftware, getSuggetstionProvider(possibleSoftwares));
usernameAutoCompletion = TextFields.bindAutoCompletion(editorUsername, getSuggetstionProvider(possibleUsernames));
});

// Update auto-completion when suggestions change
suggestionsUpdateTrigger.addListener((_, _, _) -> Platform.runLater(() -> {
if (softwareAutoCompletion != null) {
softwareAutoCompletion.dispose();
softwareAutoCompletion = TextFields.bindAutoCompletion(editorSoftware, getSuggetstionProvider(possibleSoftwares));
}
if (usernameAutoCompletion != null) {
usernameAutoCompletion.dispose();
usernameAutoCompletion = TextFields.bindAutoCompletion(editorUsername, getSuggetstionProvider(possibleUsernames));
}
}));
С Callback getSuggetstionProvider(List sourceList), который просто проверяет, начинается ли какое-либо программное обеспечение/имя пользователя с пользовательского текста.
Я пробовал заменить runLater на прослушиватель SkinProperty в текстовых полях, и он не меняется, в то время как прослушиватель SceneProperty просто делает родительская панель вообще не отображается.
Я использую Windows 11, упаковываю с помощью jpackage. Кажется, во всех случаях исключения не создаются.
Версии:
  • java 25 16 сентября 2025 г. LTS
  • javafx 25.0.1
  • controlsfx 11.2.2
  • wix 6.0.0+8c7432e
ОБНОВЛЕНИЕ: я создал пример приложения, и он по-прежнему показывает те же признаки.

Код: Выделить всё

public class App extends Application {

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Example App");
Pane pane = getPane();
primaryStage.setScene(new Scene(pane, 400, 300));
primaryStage.show();
}

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

private Pane getPane() {
AnchorPane pane = new AnchorPane();

// Add ControlsFX components to the pane
ObservableList items = FXCollections.observableArrayList();

TextField textField = new TextField();
textField.setLayoutX(50);
textField.setLayoutY(50);
textField.setPrefSize(300, 10);

textField.setOnAction(event -> {
String input = textField.getText();
if (!input.isEmpty() && !items.contains(input)) {
items.add(input);
textField.clear();
}
});

AutoCompletionBinding autoCompletion[] = new AutoCompletionBinding[1];

// Initialize auto-completion with the current items
Platform.runLater(() -> autoCompletion[0] = TextFields.bindAutoCompletion(textField, getSuggetstionProvider(items)));

// Update auto-completion when suggestions change
items.addListener((ListChangeListener) change -> {
if (autoCompletion[0] != null) {
autoCompletion[0].dispose();
autoCompletion[0] = TextFields.bindAutoCompletion(textField, getSuggetstionProvider(items));
}
});

pane.getChildren().add(textField);
return pane;
}

private Callback getSuggetstionProvider(List sourceList) {
return request -> {
String userText = request.getUserText();
if (userText == null || userText.isEmpty()) return List.of();

String lowerUserText = userText.toLowerCase();
return sourceList.stream()
.filter(s ->  s.toLowerCase().startsWith(lowerUserText))
.toList();
};
}
}

Код: Выделить всё

import org.panteleyev.jpackage.ImageType

plugins {
id 'java'
id 'application'

id 'org.openjfx.javafxplugin' version '0.1.0'
id 'org.panteleyev.jpackageplugin' version '1.7.6'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
implementation 'org.openjfx:javafx-base:25.0.1'
implementation 'org.openjfx:javafx-controls:25.0.1'
implementation 'org.openjfx:javafx-graphics:25.0.1'

implementation 'org.controlsfx:controlsfx:11.1.1'

// Use JUnit Jupiter for testing.
testImplementation libs.junit.jupiter

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// This dependency is used by the application.
implementation libs.guava
}

// Apply a specific Java toolchain to ease working on different environments.
java {
sourceCompatibility = JavaVersion.VERSION_25
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}

application {
// Define the main class for the application.
mainModule = 'org.example'
mainClass = 'org.example.App'

// JVM arguments
applicationDefaultJvmArgs = [
'--enable-native-access=javafx.graphics',
'--add-exports', 'javafx.base/com.sun.javafx.event=org.controlsfx.controls',
]
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

javafx {
version = '25.0.1'
modules = [ 'javafx.base', 'javafx.controls', 'javafx.graphics' ]
}

jar {
archiveBaseName.set(rootProject.name)
manifest {
attributes 'Implementation-Title': 'Example App', 'Main-Class': 'org.example.App'
}
}

def compileDir = rootProject.layout.projectDirectory.dir('compiled')

tasks.register('readyAllJars', Copy) {
dependsOn tasks.jar
from configurations.runtimeClasspath
from tasks.named('jar').flatMap { it.archiveFile }
into layout.buildDirectory.dir('jars')
}

jpackage {
dependsOn tasks.readyAllJars

appDescription = 'Mock application for demonstration purposes.'
appName = 'Example App'
appVersion = '0.0.1'
javaOptions = ['-Dfile.encoding=UTF-8']
module = 'org.example/org.example.App'
modulePaths = files(layout.buildDirectory.dir('jars'))
runtimeImage = file(System.getProperty('java.home'))
vendor = 'Achille004'

windows {
type = ImageType.EXE
destination = compileDir
winConsole = false
winDirChooser = true
winMenu = true
winMenuGroup = 'Achille004'
winShortcut = true
winShortcutPrompt = true
}
}
При запуске приложения без отсрочки оно не открывается (думаю, оно зависает), а добавление Platform.runLater дает тот же результат: не отображается.


Подробнее здесь: https://stackoverflow.com/questions/798 ... showing-up
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»