The problem is in this line: listView.updateUI() Calling this method causes the current UI to be uninstalled from the JList yet it is still being used to process events. This results in the NullPointerException you see. This isn't the method you want to call Try listView.revalidate() instead to cause the component to re-layout or perhaps just repaint() to get it to repaint.
The problem is in this line: listView.updateUI(); Calling this method causes the current UI to be uninstalled from the JList, yet it is still being used to process events. This results in the NullPointerException you see. This isn't the method you want to call.
Try listView.revalidate(); instead to cause the component to re-layout or perhaps just repaint() to get it to repaint.
Calling revalidate() didn't seem to have an effect, but repaint() was the trick. Thanks for the explanation of the source of the exception as well. – David S.
Jul 14 at 16:47.
Instead of the updateUI() you should call the revalidate() and repaint() method. And probably a check if the element in the list really exists wouldn't be a bad idea. @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.
VK_A) { if(list. Get(listView. GetSelectedIndex())!
= null) { list. Remove(listView. GetSelectedIndex()); listView.revalidate(); listView.repaint(); } } }.
List. RegisterKeyboardAction(this, KeyStroke. GetKeyStroke(KeyEvent.
VK_DELETE, 0), JComponent. WHEN_FOCUSED); EDIT: remove unrelated code.
I'm getting a NullPointerException in my JList, but the source of the exception seems to be the Swing event handling code. The JList has a key listener which will delete the selected item when the Delete key is pressed. The exception is only thrown on the second and all subsequent deletions from the list.
Any ideas on how to fix it?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.