Find X(item) by click jfreechart - jfreechart

I have XYdataset for plot time series.
I need find the item number on X axis just by click on chart.
below lines get item on X axis just when I click on series and if click on empty area in chart it return null. I need just item(X) not Y where ever I click on series or empty area in chart. is it possible to get this?
Thanks for help
//----------------------------------------------------------------------
CP.addChartMouseListener(new ChartMouseListener() {
#Override
public void chartMouseClicked(ChartMouseEvent cme) {
ChartEntity entity = cme.getEntity();
if (entity != null) {
System.out.println("Mouse clicked: " + entity.toString());
}
else {
System.out.println("Mouse clicked: null entity."+entity);
}
}
#Override
public void chartMouseMoved(ChartMouseEvent cme) {
}
//----------------------------------------------------------------------

Try this:
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.entity.XYItemEntity;
final class ClickedIndexMouseListener implements ChartMouseListener {
#Override
public void chartMouseMoved(ChartMouseEvent event) {
}
#Override
public void chartMouseClicked(ChartMouseEvent event) {
try {
XYItemEntity ce = (XYItemEntity) event.getEntity();
System.out.println("Item " + ce.getItem());
System.out.println("Series " + ce.getSeriesIndex());
System.out.println("X Value " + ce.getDataset().getX(ce.getSeriesIndex(), ce.getItem()));
System.out.println("Y Value " + ce.getDataset().getY(ce.getSeriesIndex(), ce.getItem()));
} catch (Exception e) {}
}
}

Related

Getting the next turn/direction in Mapbox

I'm trying to get the direction of the upcoming turn while travelling, i.e. I want to trigger an event in my app according to the direction of the upcoming turn.
I've tried using event listeners, taking help of the documentation and the provided examples but as I'm pretty new to android studio and mapbox, I've not been successful (my app either crashed or the function would never get triggered). I've also tried searching for getting the voice commands into text form or log form but have failed.
While my current code does display directions and gives voiced instructions, I can't figure out how to access either of them. I'd like to know if there's a simple way of achieving what I'm after without using any event listeners.
private MapView mapView;
private MapboxMap mapboxMap;
private PermissionsManager permissionsManager;
private LocationComponent locationComponent;
private DirectionsRoute currentRoute;
private static final String TAG = "DirectionsActivity";
private NavigationMapRoute navigationMapRoute;
private MapboxNavigation navigation;
private Button button;
private NavigationView navigationView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
// Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show();
}
#Override
public void onMapReady(#NonNull final MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
//Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show();
mapboxMap.setStyle(getString(R.string.navigation_guidance_day), new Style.OnStyleLoaded() {
#Override
public void onStyleLoaded(#NonNull Style style) {
enableLocationComponent(style);
addDestinationIconSymbolLayer(style);
mapboxMap.addOnMapClickListener(MainActivity.this);
button = findViewById(R.id.startButton);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean simulateRoute = true;
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.build();
NavigationLauncher.startNavigation(MainActivity.this, options);
}
});
}
});
}
private void addDestinationIconSymbolLayer(#NonNull Style loadedMapStyle) {
loadedMapStyle.addImage("destination-icon-id",
BitmapFactory.decodeResource(this.getResources(), R.drawable.mapbox_marker_icon_default));
GeoJsonSource geoJsonSource = new GeoJsonSource("destination-source-id");
Log.d(TAG, "addDestinationIconSymbolLayer: " + geoJsonSource);
loadedMapStyle.addSource(geoJsonSource);
SymbolLayer destinationSymbolLayer = new SymbolLayer("destination-symbol-layer-id", "destination-source-id");
destinationSymbolLayer.withProperties(
iconImage("destination-icon-id"),
iconAllowOverlap(true),
iconIgnorePlacement(true)
);
loadedMapStyle.addLayer(destinationSymbolLayer);
}
#SuppressWarnings( {"MissingPermission"})
#Override
public boolean onMapClick(#NonNull LatLng point) {
Point destinationPoint = Point.fromLngLat(point.getLongitude(), point.getLatitude());
Point originPoint = Point.fromLngLat(locationComponent.getLastKnownLocation().getLongitude(),
locationComponent.getLastKnownLocation().getLatitude());
GeoJsonSource source = mapboxMap.getStyle().getSourceAs("destination-source-id");
Log.d(TAG, "Does this even work");
Log.d(TAG, "onMapClick: " + source.toString());
if (source != null) {
source.setGeoJson(Feature.fromGeometry(destinationPoint));
}
getRoute(originPoint, destinationPoint);
button.setEnabled(true);
button.setBackgroundResource(R.color.mapboxBlue);
return true;
}
private void getRoute(Point origin, Point destination) {
NavigationRoute.builder(this)
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.build()
.getRoute(new Callback<DirectionsResponse>() {
#Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
currentRoute = response.body().routes().get(0);
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
}
navigationMapRoute.addRoute(currentRoute);
}
#Override
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
Log.e(TAG, "Error: " + throwable.getMessage());
}
});
}
#SuppressWarnings( {"MissingPermission"})
private void enableLocationComponent(#NonNull Style loadedMapStyle) {
if (PermissionsManager.areLocationPermissionsGranted(this)) {
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, loadedMapStyle);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.TRACKING);
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
#Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();
}
#Override
public void onPermissionResult(boolean granted) {
if (granted) {
enableLocationComponent(mapboxMap.getStyle());
} else {
Toast.makeText(this, R.string.user_location_permission_not_granted, Toast.LENGTH_LONG).show();
finish();
}
}
// Add the mapView's own lifecycle methods to the activity's lifecycle methods
#Override
public void onStart() {
super.onStart();
mapView.onStart();
}
#Override
public void onResume() {
super.onResume();
mapView.onResume();
// Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show();
}
#Override
public void onPause() {
super.onPause();
mapView.onPause();
}
#Override
public void onStop() {
super.onStop();
mapView.onStop();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
It sounds like you might want to look at using an event listener for a custom milestone. Here's a link to the docs:
https://docs.mapbox.com/android/navigation/overview/milestones/#milestone-event-listener

Rendering a check box with a cellFactory in TableView doesn't work as it should

I want to create the following functionality for the serieses of a line chart when the user clicks on a checkbox on a table view. The table view for items has the ObservableList of the serieses of the chart. So the following code in the controller.
The controller class injects the following from the fxml file.
#FXML
public TableView<Series<Number, Number>> tableViewStatisticsOverview;
#FXML
public TableColumn<Series<Number, Number>, String> tableColumnStatisticName;
#FXML
public TableColumn<Series<Number, Number>, Series<Number, Number>> tableColumnShowSeries;
#FXML
public TableColumn<Series<Number, Number>, Series<Number, Number>> tableColumnAction;
//later on the code
tableViewStatisticsOverview.setItems(chart.getData()); // chart is a linexy chart
//setting up the tableColumnShowSeries to show a checkbox and show and hide the series
tableColumnShowSeries.setCellValueFactory(
new Callback<TableColumn.CellDataFeatures<Series<Number, Number>, Series<Number, Number>>, ObservableValue<Series<Number, Number>>>() {
#Override
public ObservableValue<Series<Number, Number>> call(CellDataFeatures<Series<Number, Number>, Series<Number, Number>> param) {
return new ReadOnlyObjectWrapper<Series<Number, Number>>(param
.getValue());
}
});
tableColumnShowSeries.setCellFactory(
new TableCollumnCellWithCheckBoxFactoryWrapper());
As data of the table I set the whole series on the row of the table so to be able to set the node of the series visible or not according to the value of the checkbox
TableCollumnCellWithCheckBoxFactoryWrapper class
package com.nokia.avalanche.client.util.fxhelper;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.util.Callback;
public class TableCollumnCellWithCheckBoxFactoryWrapper implements
Callback<TableColumn<Series<Number, Number>, Series<Number, Number>>, TableCell<Series<Number, Number>, Series<Number, Number>>> {
#Override
public TableCell<Series<Number, Number>, Series<Number, Number>> call(TableColumn<Series<Number, Number>, Series<Number, Number>> param) {
return new CheckBoxCell();
}
}
CheckBoxCell class
public class CheckBoxCell
extends TableCell<Series<Number, Number>, Series<Number, Number>> {
Logger LOG = LogManager.getLogger(CheckBoxCell.class);
private HBox checkBoxContainer;
private CheckBox checkBoxShow;
public CheckBoxCell() {
checkBoxContainer = new HBox();
checkBoxShow = new CheckBox("");
checkBoxContainer.setAlignment(Pos.CENTER);
checkBoxShow.setSelected(true);
checkBoxContainer.getChildren().add(checkBoxShow);
}
private void addListenerOnCheckBox(Series<Number, Number> series) {
checkBoxShow.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent arg0) {
LOG.debug("Show checkbox selected: "
+ checkBoxShow.isSelected());
series.getNode().setVisible(checkBoxShow.isSelected());
if (series.getNode().isVisible()) {
series.getNode().toFront();
for (Data<Number, Number> data : series.getData()) {
data.getNode().toFront();
}
} else {
series.getNode().toBack();
for (Data<Number, Number> data : series.getData()) {
data.getNode().toBack();
}
}
}
});
}
#Override
protected void updateItem(Series<Number, Number> series, boolean empty) {
super.updateItem(series, empty);
if (!empty && series != null) {
addListenerOnCheckBox(series);
LOG.debug("Series is not empty");
LOG.debug("Updating item for series with name: " + series.getName());
setGraphic(checkBoxContainer);
} else {
LOG.debug("Series is empty");
setGraphic(null);
}
}
}
The problem is that after adding some series on the chart and they show on the table and try to click on the check box one more check box behaves the same way as the one I am clicking that is It changes it's status from checked to unchecked according to the first one I click. Debugging shows that when code enters the handle method from the action handler the check box is the same object thus unchecking the one makes the other one unchecked. Have I missed something? Is there another way to use the check box and catch the change of checkbox status?
Two things I can see:
You should set up the listener on the check box once, from the
constructor. Use getItem() to get the current series being
displayed by the cell.
In updateItem you need to update the check box to match the state of whether that series is displayed.
So I think:
public class CheckBoxCell
extends TableCell<Series<Number, Number>, Series<Number, Number>> {
Logger LOG = LogManager.getLogger(CheckBoxCell.class);
private HBox checkBoxContainer;
private CheckBox checkBoxShow;
public CheckBoxCell() {
checkBoxContainer = new HBox();
checkBoxShow = new CheckBox("");
checkBoxContainer.setAlignment(Pos.CENTER);
checkBoxShow.setSelected(true);
checkBoxContainer.getChildren().add(checkBoxShow);
addListenerOnCheckBox();
}
private void addListenerOnCheckBox() {
checkBoxShow.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent arg0) {
Series<Number, Number> series = getItem();
if (series == null) {
return ;
}
LOG.debug("Show checkbox selected: "
+ checkBoxShow.isSelected());
series.getNode().setVisible(checkBoxShow.isSelected());
if (series.getNode().isVisible()) {
series.getNode().toFront();
for (Data<Number, Number> data : series.getData()) {
data.getNode().toFront();
}
} else {
series.getNode().toBack();
for (Data<Number, Number> data : series.getData()) {
data.getNode().toBack();
}
}
}
});
}
#Override
protected void updateItem(Series<Number, Number> series, boolean empty) {
super.updateItem(series, empty);
if (!empty && series != null) {
checkBoxShow.setSelected(series.getNode().isVisible());
LOG.debug("Series is not empty");
LOG.debug("Updating item for series with name: " + series.getName());
setGraphic(checkBoxContainer);
} else {
LOG.debug("Series is empty");
setGraphic(null);
}
}
}
Not tested, so there may be other things I have missed...

Customized TreeView: setOnAction for Custom Label in TreeCell

I have made a TreeView, represented by a custom cellFactory where each cell is represented by an HBox looking like this.
How can I access the checkbox so that if you check it, a private boolean field in the corresponding EventTreeItem changes it's value?
Code:
public class EventTreeItem extends TreeItem<String>{
SimpleStringProperty item;
boolean important = true;
public EventTreeItem(boolean important, int id){
this.noNode = noNode;
super.setValue(id);
}
public EventTreeItem(){
}
public void setImportant(Boolean important){
this.important = important;
}
}
CellFactory:
public final class CustomTreeCellFactory extends TreeCell<String>{
private TextField textField;
private HBox hBox;
private HBox hBoxLeaf;
public CustomTreeCellFactory(){
try {
hBox = (HBox) FXMLLoader.load(getClass().getResource("/Views/TreCell.fxml"));
} catch (IOException e) {
System.out.println("This didn't work");
e.printStackTrace();
}
try {
hBoxLeaf = (HBox) FXMLLoader.load(getClass().getResource("/Views/TreCellLowestLevel.fxml"));
} catch (IOException e) {
System.out.println("This didn't work");
e.printStackTrace();
}
hBox.setAlignment(Pos.CENTER_LEFT);
hBoxLeaf.setAlignment(Pos.CENTER_LEFT);
}
#Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
EventTreeItem eventTreeItem = (EventTreeItem) getTreeItem();
if (getTreeView().getTreeItemLevel(getTreeItem())==1) {
setGraphic(this.hBox);
((CheckBox) ((HBox)getGraphic()).getChildren().get(3)).setSelected(((EventTreeItem) getTreeItem()).important);
((Label) hBox.getChildren().get(0)).setText(eventTreeItem.noNode.getEntryNumber() + " " + eventTreeItem.noNode.getClass().getName().split("\\.")[3]);
((Label) hBox.getChildren().get(1)).setText(eventTreeItem.noNode.getDate().toString());
}else if (getTreeView().getTreeItemLevel(getTreeItem())==2){
setGraphic(this.hBoxLeaf);
}
} else {
setGraphic(null);
}
}
}
NodeTreeView
public class NodeTreeView implements ChartView{
private FilteredListModel filteredListModel;
TreeItem<String> root;
AnchorPane parent;
TreeView treeView;
public NodeTreeView(FilteredListModel filteredListModel, TabPane tabPane) throws IOException {
this.filteredListModel = filteredListModel;
parent = (AnchorPane) FXMLLoader.load(getClass().getResource("/Views/TryTreeViewInAnchorPane.fxml"));
parent.setVisible(true);
generateTree();
}
private void generateTree() {
this.root = new EventTreeItem();
root.setExpanded(true);
filteredListModel.makeEventNodeArrays().forEach(node->{
EventTreeItem item = new EventTreeItem((EventNoNode) node);
EventTreeItem item2 = new EventTreeItem();
root.getChildren().add(item);
item.getChildren().add(item2);
});
treeView = (TreeView) parent.getChildren().get(0);
treeView.setRoot(root);
treeView.setShowRoot(false);
treeView.setEditable(true);
treeView.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
#Override
public TreeCell<String> call(TreeView<String> param) {
return new CustomTreeCellFactory();
}
});
}
}
You can add a listener to checkbox's selectedProperty in your CustomTreeCellFactory constructor (which is not a factory, btw; you should call it CustomTreeCell instead):
public CustomTreeCellFactory() {
// ...
CheckBox checkbox = ...;
checkbox.selectedProperty().addListener((obs, wasSelected, isSelected) -> {
((EventTreeItem) getTreeItem()).important = isSelected;
});
}
Btw, it is probably a better idea to make the "important" flag be part of the item, i.e. instead of TreeView<String>, you would have TreeView<MyItem> where MyItem is
class MyItem {
String item;
boolean important;
MyItem(String item, boolean important) {
this.item = item;
this.important = important;
}
}

JavaFX ComboBox setButtonCell

i need help about settings the combobox buttonCell.
I use a combobox that show data from an observable list that contains data from a table with two columns, "Step" and "NextStep" (NextStep contains one item inserted in column Step); what i need to do is to show the combobox listcell with the list of "Step" and the buttoncell with the relative "NextStep". Now, i can see the listcell correctly but my buttoncell is always empty.
The code:
// SET THE VALUE STEP TO THE LISTCELL
comboStatoSuccessivo.setCellFactory(new Callback<ListView<StatoEsiti>, ListCell<StatoEsiti>>() {
#Override public ListCell<StatoEsiti> call(ListView<StatoEsiti> p) {
return new ListCell<StatoEsiti>() {
#Override
protected void updateItem(StatoEsiti t, boolean bln) {
super.updateItem(t, bln);
if(t != null){
setText(t.statoProperty().getValue());
System.out.println("SET PROPERTY " + t.statoProperty().getValue());
} else {
setText(null);
}
}
};
}
});
// SET THE VALUE NEXTSTEP TO THE BUTTONCELL
comboStatoSuccessivo.setButtonCell(new ListCell<StatoEsiti>() {
#Override
protected void updateItem(StatoEsiti t, boolean bln) {
super.updateItem(t, bln);
if (t != null) { <<<<<<<<<<<<<<-------------ALWAYS NULL----WHY??????
setText(t.statoSuccessivoProperty().getValue());
System.out.println("SET PROPERTY BUTTONCELL " + t.statoSuccessivoProperty().getValue());
} else {
setText(null);
System.out.println("SET PROPERTY BUTTONCELL NULL");
}
}
});
Thanks in advance.
I have looked into your use case with the following demo SSCCE code.
It is working as expected, like as when the item is selected from the combobox's dropmenu the buttoncell is updated with related "nextStep":
public class ComboDemo extends Application {
#Override
public void start(Stage primaryStage) {
List<Person> list = new ArrayList<Person>();
list.add(new Person("step 1212", 12));
list.add(new Person("step 4545", 45));
list.add(new Person("step 5656", 56));
list.add(new Person("step 9090", 90));
ComboBox<Person> comboBox = new ComboBox<>(FXCollections.observableList(list));
comboBox.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() {
#Override
public ListCell<Person> call(ListView<Person> p) {
return new ListCell<Person>() {
#Override
protected void updateItem(Person t, boolean bln) {
super.updateItem(t, bln);
if (t != null) {
setText(t.getStepProperty().getValue());
System.out.println("SET PROPERTY " + t.getStepProperty().getValue());
} else {
setText(null);
}
}
};
}
});
// SET THE VALUE NEXTSTEP TO THE BUTTONCELL
comboBox.setButtonCell(new ListCell<Person>() {
#Override
protected void updateItem(Person t, boolean bln) {
super.updateItem(t, bln);
if (t != null) {
setText(t.getNextStepProperty().getValue().toString());
System.out.println("SET PROPERTY BUTTONCELL " + t.getNextStepProperty().getValue());
} else {
setText(null);
System.out.println("SET PROPERTY BUTTONCELL NULL");
}
}
});
StackPane root = new StackPane();
root.getChildren().add(comboBox);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static class Person {
private StringProperty stepProperty = new SimpleStringProperty();
private IntegerProperty nextStepProperty = new SimpleIntegerProperty();
public Person(String step, Integer nextStep) {
this.stepProperty.setValue(step);
this.nextStepProperty.setValue(nextStep);
}
public StringProperty getStepProperty() {
return stepProperty;
}
public void setStepProperty(StringProperty stepProperty) {
this.stepProperty = stepProperty;
}
public IntegerProperty getNextStepProperty() {
return nextStepProperty;
}
public void setNextStepProperty(IntegerProperty nextStepProperty) {
this.nextStepProperty = nextStepProperty;
}
}
public static void main(String[] args) {
launch(args);
}
}
Compare it with yours.

JavaFX ComboBox set Items from ObservableList

i need help to get a specified list of items from ObservableList and add them to a combo box.
My ObservableList contains value received from DB (in specific a table with just 3 columns) and i want to show only one column value in combo box. When combo box is selected the other values are charged in 2 textfield.
Code as follows.
ImportAccettazioniModel:
public ObservableList<Impostazioni> listImpostazioni = FXCollections.observableArrayList();
public static class Impostazioni {
private final StringProperty rowid;
private final StringProperty nome;
private final StringProperty operatore;
private final StringProperty delimitatore;
private Impostazioni(String Rowid, String Nome, String Operatore, String Delimitatore) {
this.rowid = new SimpleStringProperty(Rowid);
this.nome = new SimpleStringProperty(Nome);
this.operatore = new SimpleStringProperty(Operatore);
this.delimitatore = new SimpleStringProperty(Delimitatore);
}
public StringProperty rowidProperty() { return rowid; }
public StringProperty nomeProperty() { return nome; }
public StringProperty operatoreProperty() { return operatore; }
public StringProperty delimitatoreProperty() { return delimitatore; }
}
ImportAccettazioniController:
#FXML
private ComboBox<ImportAccettazioniModel.Impostazioni> comboCaricaNome;
// get data from model to popupate combobox
public final void getImpostazioniDataFields() {
comboCaricaNome.getItems().clear();
comboCaricaNome.setItems(model.listImpostazioni);
comboCaricaNome.setCellFactory(new Callback<ListView<Impostazioni>, ListCell<Impostazioni>>() {
#Override public ListCell<Impostazioni> call(ListView<Impostazioni> p) {
return new ListCell<Impostazioni>() {
#Override
protected void updateItem(Impostazioni t, boolean bln) {
super.updateItem(t, bln);
if(t != null){
setText(t.nomeProperty().toString().toUpperCase());
System.out.println("SET PROPERTY " + t.nomeProperty().toString());
} else {
setText(null);
}
}
};
}
});
}
comboCaricaNome.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ImportAccettazioniModel.Impostazioni>() {
#Override public void changed(ObservableValue<? extends ImportAccettazioniModel.Impostazioni> observable,ImportAccettazioniModel.Impostazioni oldValue, ImportAccettazioniModel.Impostazioni newValue) {
setTextFields(newValue);
}
});
//set data to textfield with the selected combo box
private void setTextFields(Impostazioni listImpostazioni) {
//setRowid(Impostazioni.rowidProperty().getValue());
if (comboCaricaNome.getItems().isEmpty()) {
editCaricaOperatore.setText("");
editCaricaDelimitatore.setText("");
} else {
editCaricaOperatore.setText(listImpostazioni.operatoreProperty().getValue());
editCaricaDelimitatore.setText(listImpostazioni.delimitatoreProperty().getValue());
}
}
Now, the logic seems to work but my combo box doesn't contain the value nomeProperty().
How can i solve?
Thanks in advance
To get the observed value of the JavaFX Property use Property.get() or Property.getValue().
By convention, the Java developers override toString() method to not show message for customers, instead it is used for internal usages by another developers.
As a result, the line
setText(t.nomeProperty().toString().toUpperCase());
should be
setText(t.nomeProperty().getValue().toUpperCase());
UPDATE:
Since you are using the ComboBox rather than ChoiceBox, you should also override default button cell property of combobox, according to your needs:
comboCaricaNome.setButtonCell(new ListCell<Impostazioni>() {
#Override
protected void updateItem(Impostazioni t, boolean bln) {
super.updateItem(t, bln);
if (t != null) {
setText(t.nomeProperty().getValue().toUpperCase());
} else {
setText(null);
}
}
});
As you can see this is the same ListCell which is set for cellFactory. Refactoring is up to you, or of course you can implement a listcell with different content as well.

Resources