ListView not clickable with a mouse [on hold]











up vote
-2
down vote

favorite












I made a ListView but when I try to select an item from it with the mouse it doesn't works. The only way to select the item is by using the arrows on keyboard. This is my fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<ListView fx:id="listView" layoutY="29.0" mouseTransparent="false" prefHeight="371.0" prefWidth="240.0" /></AnchorPane>


This is the Controller of the list:



public class ListController {
@FXML
private ListView<Email> listView ;
private DataModel model ;

public void initModel(DataModel model) {
if (this.model != null) {
throw new IllegalStateException("Model can only be initialized once");
}
this.model = model ;
model.loadData(null);
listView.setItems(model.getEmailList());
listView.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) ->
model.setCurrentEmail(newSelection));

model.currentEmailProperty().addListener((obs, oldEmail, newEmail) -> {
if (newEmail == null) {
listView.getSelectionModel().clearSelection();
} else {
listView.getSelectionModel().select(newEmail);
}
});

listView.setCellFactory(lv -> new ListCell<Email>() {
@Override
public void updateItem(Email mail, boolean empty) {
super.updateItem(mail, empty);
if (empty) {
setText(null);
} else {
setText(mail.getMittente());
}
}
});
}


And this is where I declare it:



public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));

AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load());

ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
MenuBarController menuController = menuLoader.getController();









share|improve this question







New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612 Nov 13 at 19:16


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Toby Speight
    Nov 13 at 16:57










  • The code does what I want, but I would like to improve it by adding the mouse listener
    – Dorco Pio
    Nov 13 at 19:22















up vote
-2
down vote

favorite












I made a ListView but when I try to select an item from it with the mouse it doesn't works. The only way to select the item is by using the arrows on keyboard. This is my fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<ListView fx:id="listView" layoutY="29.0" mouseTransparent="false" prefHeight="371.0" prefWidth="240.0" /></AnchorPane>


This is the Controller of the list:



public class ListController {
@FXML
private ListView<Email> listView ;
private DataModel model ;

public void initModel(DataModel model) {
if (this.model != null) {
throw new IllegalStateException("Model can only be initialized once");
}
this.model = model ;
model.loadData(null);
listView.setItems(model.getEmailList());
listView.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) ->
model.setCurrentEmail(newSelection));

model.currentEmailProperty().addListener((obs, oldEmail, newEmail) -> {
if (newEmail == null) {
listView.getSelectionModel().clearSelection();
} else {
listView.getSelectionModel().select(newEmail);
}
});

listView.setCellFactory(lv -> new ListCell<Email>() {
@Override
public void updateItem(Email mail, boolean empty) {
super.updateItem(mail, empty);
if (empty) {
setText(null);
} else {
setText(mail.getMittente());
}
}
});
}


And this is where I declare it:



public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));

AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load());

ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
MenuBarController menuController = menuLoader.getController();









share|improve this question







New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612 Nov 13 at 19:16


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Toby Speight
    Nov 13 at 16:57










  • The code does what I want, but I would like to improve it by adding the mouse listener
    – Dorco Pio
    Nov 13 at 19:22













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I made a ListView but when I try to select an item from it with the mouse it doesn't works. The only way to select the item is by using the arrows on keyboard. This is my fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<ListView fx:id="listView" layoutY="29.0" mouseTransparent="false" prefHeight="371.0" prefWidth="240.0" /></AnchorPane>


This is the Controller of the list:



public class ListController {
@FXML
private ListView<Email> listView ;
private DataModel model ;

public void initModel(DataModel model) {
if (this.model != null) {
throw new IllegalStateException("Model can only be initialized once");
}
this.model = model ;
model.loadData(null);
listView.setItems(model.getEmailList());
listView.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) ->
model.setCurrentEmail(newSelection));

model.currentEmailProperty().addListener((obs, oldEmail, newEmail) -> {
if (newEmail == null) {
listView.getSelectionModel().clearSelection();
} else {
listView.getSelectionModel().select(newEmail);
}
});

listView.setCellFactory(lv -> new ListCell<Email>() {
@Override
public void updateItem(Email mail, boolean empty) {
super.updateItem(mail, empty);
if (empty) {
setText(null);
} else {
setText(mail.getMittente());
}
}
});
}


And this is where I declare it:



public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));

AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load());

ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
MenuBarController menuController = menuLoader.getController();









share|improve this question







New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I made a ListView but when I try to select an item from it with the mouse it doesn't works. The only way to select the item is by using the arrows on keyboard. This is my fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<ListView fx:id="listView" layoutY="29.0" mouseTransparent="false" prefHeight="371.0" prefWidth="240.0" /></AnchorPane>


This is the Controller of the list:



public class ListController {
@FXML
private ListView<Email> listView ;
private DataModel model ;

public void initModel(DataModel model) {
if (this.model != null) {
throw new IllegalStateException("Model can only be initialized once");
}
this.model = model ;
model.loadData(null);
listView.setItems(model.getEmailList());
listView.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) ->
model.setCurrentEmail(newSelection));

model.currentEmailProperty().addListener((obs, oldEmail, newEmail) -> {
if (newEmail == null) {
listView.getSelectionModel().clearSelection();
} else {
listView.getSelectionModel().select(newEmail);
}
});

listView.setCellFactory(lv -> new ListCell<Email>() {
@Override
public void updateItem(Email mail, boolean empty) {
super.updateItem(mail, empty);
if (empty) {
setText(null);
} else {
setText(mail.getMittente());
}
}
});
}


And this is where I declare it:



public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));

AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load());

ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
MenuBarController menuController = menuLoader.getController();






java javafx






share|improve this question







New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 13 at 13:55









Dorco Pio

1




1




New contributor




Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Dorco Pio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612 Nov 13 at 19:16


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612 Nov 13 at 19:16


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Toby Speight, 200_success, Sᴀᴍ Onᴇᴌᴀ, πάντα ῥεῖ, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Toby Speight
    Nov 13 at 16:57










  • The code does what I want, but I would like to improve it by adding the mouse listener
    – Dorco Pio
    Nov 13 at 19:22














  • 1




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Toby Speight
    Nov 13 at 16:57










  • The code does what I want, but I would like to improve it by adding the mouse listener
    – Dorco Pio
    Nov 13 at 19:22








1




1




I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Toby Speight
Nov 13 at 16:57




I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Toby Speight
Nov 13 at 16:57












The code does what I want, but I would like to improve it by adding the mouse listener
– Dorco Pio
Nov 13 at 19:22




The code does what I want, but I would like to improve it by adding the mouse listener
– Dorco Pio
Nov 13 at 19:22















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Terni

A new problem with tex4ht and tikz

Sun Ra