java - javafx create ComboBox TableCell -


I am trying to create a custom tablecale in my table view. I would like to display this a combo box, where I can select a string value, and then display the string value as if this was user input. The idea is that the fourth user does not know that the permission is granted, so that they can simply choose one of them in the ComboBox.

I think that trying to make their own "ComboBoxCell" to do but it does not work as expected:

  public class ComboBoxCell Teblkel Extended & Lt; ClassesProperty, String & gt; {Private combo box & lt; String & gt; combo box; Public Combo Box () {} @ Override Public Zero Start () {super.startEdit (); If (combo box == empty) {createComboBox (); } Setgraphic (combo box); SetContentDisplay (ContentDisplay.GRAPHIC_ONLY); } @ Override Public Zero Cancel () {super.cancelEdit (); SetText (String.valueOf (GetItem ())); SetContentDisplay (ContentDisplay.TEXT_ONLY); } Public Zero update item (string item, boolean empty) {super. Additional item (item, empty); If (empty) {set text (zero); SetGraphic (zero); } Else {if () is) {if (comboBox! = Null) {comboBox.setValue (getString ()); } Setgraphic (combo box); SetContentDisplay (ContentDisplay.GRAPHIC_ONLY); } And {setText (getString ()); SetContentDisplay (ContentDisplay.TEXT_ONLY); }}} Private Zero createComboBox () {// ClassesController.getLevelChoice () string indicates that the notified list = new ComboBox & lt; & Gt; (ClassesController.getLevelChoice ()); ComboBox.setMinWidth (this.getWidth () - this.getGraphicTextGap () * 2); comboBox.setOnKeyPressed (New eventhandler & LT; KeyEvent & gt; () {@Override public void handle (KeyEvent t) {if (t.getCode () == KeyCode.ENTER) {commitEdit (comboBox.getSelectionModel () getSelectedItem () ) ;.} Else if (t.getCode () == KeyCode.ESCAPE) {cancelEdit ();}}}); } Private string getString () {returnItem () == empty? "": GetItem (). ToString (); }}  

Then in my "main" application:

  levelChoice = FXCollections.observableArrayList (new String ( "Bla"), new String ( "Blo ")); // Level column: string value callback & lt; Table Columns, Tableclass & gt; ComboBoxFactory = new callback & lt; TableColumn, TableCell & gt; () {@Override Public TableCell Call (TableColumn P) {Return New ComboBoxCell (); }}; LevelColumn.setCellValueFactory (New Property Value Factor & lt; Classes Property, String & gt; ("Level")); LevelColumn.setCellFactory (comboBoxFactory);  

Any ideas? ! Thank you

I've got the solution:

  levelChoice = FXCollections. ObservableArrayList (new string ("blank"), new string ("blow"); LevelColumn.setCellValueFactory (New Property Value Factor & lt; Classes Property, String & gt; ("Level")); LevelColumn.setCellFactory (ComboBoxTableCell.forTableColumn (levelChoice)); LevelColumn.setOnEditCommit (new Iventhandlr & lt; CellEditEvent & lt; ClassesProperty, String & gt; & gt; () {@Override public void handle (CellEditEvent & lt; ClassesProperty, String & gt; t) {((Clasesproperti) T. Gettablaviav (). Getitms (). Kgettableposisn (). Getro ()). Setlvel (Tikgetnevvlua ());};});  

Comments