-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed the name field in Sprite import panel #778 #811
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, your first Pull Request in the LITIENGINE repository! You have earned the rank of "contributor" - let us know your nickname in the Forum and on Discord so we can reward you with the new role :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I have suggested some improvements below.
@@ -182,7 +180,7 @@ public Component getListCellRendererComponent( | |||
textField = new JTextField(); | |||
ControlBehavior.apply(textField); | |||
textField.setColumns(10); | |||
textField.addActionListener(e -> fileList.getSelectedValue().setName(textField.getText())); | |||
fileList.addListSelectionListener(e -> textField.setText(fileList.getSelectedValue().getName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the updates should be triggered as soon as the text field is updated, rather than when the selection in the file list changes. Try this:
fileList.addListSelectionListener(e -> textField.setText(fileList.getSelectedValue().getName())); | |
textField.getDocument().addDocumentListener(new DocumentListener() { | |
@Override | |
public void insertUpdate(DocumentEvent e) { | |
updateSelectedFile(); | |
} | |
@Override | |
public void removeUpdate(DocumentEvent e) { | |
updateSelectedFile(); | |
} | |
@Override | |
public void changedUpdate(DocumentEvent e) { | |
updateSelectedFile(); | |
} | |
}); |
Then later, define the updateSelectedFile
method as follows:
private void updateSelectedFile() {
int selectedIndex = fileList.getSelectedIndex();
if (selectedIndex != -1) {
SpriteFileWrapper selectedFile = fileListModel.getElementAt(selectedIndex);
selectedFile.setName(textField.getText());
fileList.repaint();
}
}
I will make those changes tomorrow morning. |
gurkenlabs#778 where the sprite name is updated simultaneously in the list and in the text field
#778
utiliti-bug-fix-778.mp4
I got the Sprite name in the text field which updates the Sprite's name in the application.