Exception in thread "JavaFX Application Thread" [Résolu/Fermé]
Signaler
moi411
greg6614
- Messages postés
- 180
- Date d'inscription
- samedi 22 novembre 2003
- Statut
- Membre
- Dernière intervention
- 25 juin 2017
greg6614
- Messages postés
- 592
- Date d'inscription
- vendredi 7 août 2009
- Statut
- Membre
- Dernière intervention
- 3 juin 2017
A voir également:
- Exception in thread "javafx application thread" java.lang.nullpointerexception
- Exception in thread "javafx application thread" - Meilleures réponses
- Exception in thread "JavaFX Application Thread" ✓ - Forum - Java
- Exception in thread "main" java.lang.noclassdeffounderror: javafx/application/application ✓ - Forum - Java
- Exception in thread "main" java.lang.stackoverflowerror ✓ - Forum - Java
- Exception in thread "main" java.lang.nullpointerexception ✓ - Forum - Java
- Exception in thread "main" java.lang.outofmemoryerror: java heap space ✓ - Forum - Java
2 réponses
greg6614
- Messages postés
- 592
- Date d'inscription
- vendredi 7 août 2009
- Statut
- Membre
- Dernière intervention
- 3 juin 2017
Hello,
Ton objet Label est null, surement un probléme de cast, essai ceci :
En espérant t'avoir aider
Greg
Ton objet Label est null, surement un probléme de cast, essai ceci :
protected void itemClickEvent(MouseEvent event) { String l = event.getSource().toString(); detailsTextField.setText(l); }
En espérant t'avoir aider
Greg
moi411
- Messages postés
- 180
- Date d'inscription
- samedi 22 novembre 2003
- Statut
- Membre
- Dernière intervention
- 25 juin 2017
Re,
Merci pour ton aide... En fait j'ai posté sur toute une série de forum et on m'avait déjà envoyé une solution!
Désolé pour le retard!
Je poste d'ailleurs le code:
--
Merci pour ton aide... En fait j'ai posté sur toute une série de forum et on m'avait déjà envoyé une solution!
Désolé pour le retard!
Je poste d'ailleurs le code:
package combotest; import javafx.application.Application; import javafx.beans.InvalidationListener; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.SplitPane; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class Main extends Application { private static final class ComBoxItemPerso { private final String value; private final Image icon; public ComBoxItemPerso(final String value, final String iconUrl) { this.value = value; this.icon = new Image(iconUrl); } public String getValue() { return value; } public Image getIcon() { return icon; } } private static final class ComBoxItemPersoListCell extends ListCell<ComBoxItemPerso> { private final ComboBox<ComBoxItemPerso> parent; private final Label rightLabel = new Label(); private final ImageView leftImage = new ImageView(); private final SplitPane splitPane = new SplitPane(leftImage, rightLabel); public ComBoxItemPersoListCell(final ComboBox<ComBoxItemPerso> parent) { super(); // Oblige de rajouter tout ce qui suit a cause du splitpane. this.parent = parent; leftImage.setOnMousePressed(this::selectInCombo); // rightLabel.setStyle("-fx-border-color: green;"); rightLabel.setMaxWidth(Double.MAX_VALUE); rightLabel.setOnMousePressed(this::selectInCombo); } private ComBoxItemPerso lastItem; @Override protected void updateItem(final ComBoxItemPerso item, final boolean empty) { super.updateItem(item, empty); lastItem = item; Node graphic = null; leftImage.setImage(null); rightLabel.setText(null); if (!empty && item != null) { leftImage.setImage(item.getIcon()); rightLabel.setText(item.getValue()); graphic = splitPane; } setGraphic(graphic); setText(null); } private void selectInCombo(final MouseEvent mouseEvent) { if (parent != null) { parent.getSelectionModel().select(lastItem); } } } private final TextField detailsTextField = new TextField(); private final ComboBox<ComBoxItemPerso> myComboBox = new ComboBox<>(); @Override public void start(Stage primaryStage) { detailsTextField.setEditable(false); //comboBox myComboBox.setPrefWidth(176.5); final ObservableList<ComBoxItemPerso> options = FXCollections.observableArrayList(new ComBoxItemPerso("1", getClass().getResource("1.png").toExternalForm()), new ComBoxItemPerso("2", getClass().getResource("2.png").toExternalForm()), new ComBoxItemPerso("3", getClass().getResource("3.png").toExternalForm())); myComboBox.setItems(options); myComboBox.setButtonCell(new ComBoxItemPersoListCell(null)); myComboBox.setCellFactory(listView -> new ComBoxItemPersoListCell(myComboBox)); myComboBox.valueProperty().addListener(valueInvalidationListener); final StackPane center = new StackPane(); center.getChildren().add(myComboBox); final BorderPane root = new BorderPane(center, detailsTextField, null, null, null); final Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Test"); primaryStage.setScene(scene); primaryStage.show(); } private final InvalidationListener valueInvalidationListener = observable -> { final ComBoxItemPerso item = myComboBox.getValue(); final String text = (item == null) ? null : item.getValue(); detailsTextField.setText(text); }; public static void main(String[] args) { launch(args); } }
--