diff --git a/src/main/java/seedu/address/ui/NotesWindow.java b/src/main/java/seedu/address/ui/NotesWindow.java index fe9dce39180..c5a85e1bcc7 100644 --- a/src/main/java/seedu/address/ui/NotesWindow.java +++ b/src/main/java/seedu/address/ui/NotesWindow.java @@ -1,11 +1,12 @@ package seedu.address.ui; -import java.util.List; import java.util.logging.Logger; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; @@ -23,7 +24,7 @@ public class NotesWindow extends UiPart { private static final String FXML = "NotesWindow.fxml"; @FXML - private ListView notesListView; + private ListView notesListView; private final Person person; @@ -67,16 +68,29 @@ public void hide() { getRoot().hide(); } - public void focus() { - getRoot().requestFocus(); - } - - private void populateListView(List notes) { - ObservableList notesObservableList = FXCollections.observableArrayList(); - for (Note note : notes) { - notesObservableList.add(note.toString()); - } + private void populateListView(ObservableList notes) { + ObservableList notesObservableList = FXCollections.observableArrayList(notes); notesListView.setItems(notesObservableList); + notesListView.setCellFactory(listView -> new ListCell() { + @Override + protected void updateItem(Note note, boolean empty) { + super.updateItem(note, empty); + if (empty || note == null) { + setText(null); + setGraphic(null); + } else { + Label label = new Label((getIndex() + 1) + ". " + note.toString()); + label.setWrapText(true); + label.prefWidthProperty().bind(listView.widthProperty().subtract(40)); + setGraphic(label); + } + } + }); + + // make sure the width is always correct even after resizing the window + notesListView.widthProperty().addListener((observable) -> { + notesListView.refresh(); + }); } @FXML @@ -85,7 +99,7 @@ void handleClose() { stage.close(); } - public ListView getNotesListView() { + public ListView getNotesListView() { return notesListView; } } diff --git a/src/main/resources/view/NotesWindow.fxml b/src/main/resources/view/NotesWindow.fxml index 4f2db31b55d..14b71644227 100644 --- a/src/main/resources/view/NotesWindow.fxml +++ b/src/main/resources/view/NotesWindow.fxml @@ -6,7 +6,7 @@ - @@ -15,9 +15,7 @@