Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cant delete or add item to Jlist as nthing happens

807599Feb 20 2007 — edited Feb 22 2007
Hi all,
regarding the first part where pass of string array into object array. I have done it (thanks again for the help). But regarding the add and remove elements from the Jlist cant be done.. below is my code for the delete button when press. I cast it into int for the ManualList.getSelectedIndex();(at part A) but cant display and keep having a error call
java.lang.NullPointerException at ManualChange&ValueReporter.valueChanged
code for value reporter is at part B

Part A
private void deleteMouseClicked(MouseEvent e)
{
int n =(int)ManualList.getSelectedIndex();
if (!(n < 0) || (n > listModel.size()))
{
listModel.remove(n);
}
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
}

Part B

private class ValueReporter implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
// if (!event.getValueIsAdjusting())
// gettext.setText(ManualList.getSelectedValue().toString());
ManualList.repaint();
ManualList.revalidate();

}

Any help is greatly appreciated.



alright, i redo part A the code is shown below but i still cant get the display out.
Is there some problem in my code? or is the repaint and revalidate thing wrong usage here ? Need help regarding this. Thanks


int n =ManualList.getSelectedIndex();
if (!(n < 0) || (n > listModel.size()))
{
listModel.removeElement(arrayObject[n]);
}
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2007
Added on Feb 20 2007
13 comments
489 views