Re: Button events in ListCells not working
https://javafx-jira.kenai.com/browse/RT-35864 -- Daniel Opitz On 14 Feb 2014 at 08:09:20, Jonathan Giles (jonathan.gi...@oracle.com) wrote: File a bug in Jira and I can take a closer look in the coming days. Thanks! -- Jonathan Sent from a touch device. Please excuse my brevity. On 14 February 2014 19:46:12 GMT+13:00, Daniel Opitz wrote: Hi, I found something that looks like a bug. When a Button is placed in a ListCell (or probably any other Cell) its onAction event is never fired and onMouseClicked very rarely and seemingly randomly. Or is it me doing things the wrong way? Using the JDK8 RC. Here is some example code: import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.stage.Stage; public class Testing extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { ObservableList strings = FXCollections.observableArrayList(); strings.addAll("text", "another"); ListView list = new ListView<>(strings); list.setCellFactory(cell -> new ButtonCell()); Scene s = new Scene(list, 300, 400); primaryStage.setScene(s); primaryStage.show(); } private class ButtonCell extends ListCell { @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); setGraphic(null); } else { setText(item); Button b = new Button("button"); b.setOnAction(action -> System.out.println("zam")); b.setOnMouseClicked(action -> System.out.println("bam")); setGraphic(b); } } } } -- Daniel Opitz
Re: Button events in ListCells not working
File a bug in Jira and I can take a closer look in the coming days. Thanks! -- Jonathan Sent from a touch device. Please excuse my brevity. On 14 February 2014 19:46:12 GMT+13:00, Daniel Opitz wrote: >Hi, > >I found something that looks like a bug. When a Button is placed in a >ListCell (or probably any other Cell) its onAction event is never fired >and onMouseClicked very rarely and seemingly randomly. Or is it me >doing things the wrong way? Using the JDK8 RC. Here is some example >code: > >import javafx.application.Application; >import javafx.collections.FXCollections; >import javafx.collections.ObservableList; >import javafx.scene.Scene; >import javafx.scene.control.Button; >import javafx.scene.control.ListCell; >import javafx.scene.control.ListView; >import javafx.stage.Stage; > >public class Testing extends Application { > > public static void main(String[] args) { > launch(args); > } > > @Override > public void start(Stage primaryStage) throws Exception { > ObservableList strings = >FXCollections.observableArrayList(); > strings.addAll("text", "another"); > ListView list = new ListView<>(strings); > list.setCellFactory(cell -> new ButtonCell()); > Scene s = new Scene(list, 300, 400); > primaryStage.setScene(s); > primaryStage.show(); > } > > private class ButtonCell extends ListCell { > > @Override > protected void updateItem(String item, boolean empty) { > super.updateItem(item, empty); > if (empty) { > setText(null); > setGraphic(null); > } else { > setText(item); > Button b = new Button("button"); > b.setOnAction(action -> System.out.println("zam")); > b.setOnMouseClicked(action -> >System.out.println("bam")); > setGraphic(b); > } > } > } >} > > >-- >Daniel Opitz