Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

javafx combobox cell

@FXML AnchorPane root;
@FXML ComboBox<UserDTO> cmbUsers;
List<UserDTO> users;
public class GateInController implements Initializable {
@Override   
public void initialize(URL location, ResourceBundle resources) {
        users = UserService.getListOfUsers();
        cmbUsers.setItems(FXCollections.observableList(users));
        cmbUsers.getSelectionModel().selectFirst();
        // list of values showed in combo box drop down
        cmbUsers.setCellFactory(new Callback<ListView<UserDTO>,ListCell<UserDTO>>(){
            @Override
            public ListCell<UserDTO> call(ListView<UserDTO> l){
                return new ListCell<UserDTO>(){
                    @Override
                    protected void updateItem(UserDTO item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item == null || empty) {
                            setGraphic(null);
                        } else {
                            setText(item.getUserId()+"    "+item.getUserNm());
                        }
                    }
                } ;
            }
        });
        //selected value showed in combo box
        cmbUsers.setConverter(new StringConverter<UserDTO>() {
              @Override
              public String toString(UserDTO user) {
                if (user == null){
                  return null;
                } else {
                  return user.getUserId();
                }
              }

            @Override
            public UserDTO fromString(String userId) {
                return null;
            }
        });
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java to python 
Java :: java code to get all leaf nodes of a xml 
Java :: how does plus works in Java 
Java :: How to send saved CSV file via email 
Java :: java public keyword 
Java :: l datetime anne month jour heure minute second in java 
Java :: netbens setdefaultbutton 
Java :: exoplayer how to put loader while video is still loading android java 
Java :: java regex of eauations 
Java :: java and python begineers mcq with answers 
Java :: session management in java spring boot for login logut 
Java :: instance block in java 
Java :: English print format number in java 
Java :: find the key that has the least value in map java 
Java :: Which of the below is a correct identifier for a method name in Java * 2 points 0start #stop 0_start *start# 
Java :: split email on dot java 
Java :: destroy fragent after navigating 
Java :: what is difference between constant and final in java 
Java :: print method in java 
Java :: create object of hashMap with integer key and String value 
Java :: java function that returns the index of the largest value in an array 
Java :: acceder a elementos de list java 
Java :: android studio setbackgroundcolor drawable 
Java :: @Bean public ModelMapper modelMapper() { ModelMapper modelMapper = new ModelMapper(); modelMapper.getConfiguration() .setMatchingStrategy(MatchingStrategies.STRICT); } 
Java :: getBatteryPercentage android studio 
Java :: how to avoid outside click of alerdialoge android 
Java :: jdbc insert example from input values 
Java :: why fields should be final in immutable class? 
Java :: online java http request demo 
Java :: stack java 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =