|
|
Removing an item from a Jlist
Hi all,
I m currently developing a java application where information from a
file is populated into a JList. The user should be able to select an
item from the JList and then once the user presses the delete button
the item that the user selected should therefore be removed from the
JList. How would I go about doing this.
Any help in this matter would be highly appreciated. Thank you
|
|
0
|
|
|
|
Reply
|
christopher_board
|
2/28/2008 2:10:53 PM |
|
I think this link will satisfy your needs and maybe more.
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
|
|
0
|
|
|
|
Reply
|
TheBigPJ
|
2/28/2008 2:47:21 PM
|
|
On 28 Feb, 14:47, TheBigPJ <TheBi...@gmail.com> wrote:
> I think this link will satisfy your needs and maybe more.
>
> http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
Hi all. Thanks for the replies. I have had a look at the website
mentioned above by TheBigPJ and have entered the following the code
into my program:
int index = lstComputerExceptions.getSelectedIndex();
lstComputerExceptions.remove(index);
lstComputerExceptions.setSelectedIndex(index);
lstComputerExceptions.ensureIndexIsVisible(index);
}
However when I run it always comes up with the following error
message:
ception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
at java.awt.Container.remove(Unknown Source)
at
remoteshutdown.ExceptionsList.btnDelete_actionPerformed(ExceptionsList.java:
191)
at
remoteshutdown.ExceptionsList_btnDelete_actionAdapter.actionPerformed(ExceptionsList.java:
227)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at
remoteshutdown.mainScreen.jMenuOptionsExceptions_actionPerformed(mainScreen.java:
947)
at remoteshutdown.mainScreen
$mainScreen_jMenuOptionsExceptions_ActionAdapter.actionPerformed(mainScreen.java:
1113)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI
$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.awt.Container.remove(Unknown Source)
at
remoteshutdown.ExceptionsList.btnDelete_actionPerformed(ExceptionsList.java:
191)
at
remoteshutdown.ExceptionsList_btnDelete_actionAdapter.actionPerformed(ExceptionsList.java:
227)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at
remoteshutdown.mainScreen.jMenuOptionsExceptions_actionPerformed(mainScreen.java:
947)
at remoteshutdown.mainScreen
$mainScreen_jMenuOptionsExceptions_ActionAdapter.actionPerformed(mainScreen.java:
1113)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI
$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Does anyone have any ideas as to why this could be happening. I have
had a look on the Internet for the error message but have not found
anyhing that seems to be of any relevance.
Any help in this matter would be highly appreciated.
Thank you
|
|
0
|
|
|
|
Reply
|
christopher_board
|
2/28/2008 3:49:01 PM
|
|
On 28 Feb, 15:49, christopher_bo...@yahoo.co.uk wrote:
> On 28 Feb, 14:47, TheBigPJ <TheBi...@gmail.com> wrote:
>
> > I think this link will satisfy your needs and maybe more.
>
> >http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
>
> Hi all. Thanks for the replies. I have had a look at the website
> mentioned above by TheBigPJ and have entered the following the code
> into my program:
> int index = lstComputerExceptions.getSelectedIndex();
> lstComputerExceptions.remove(index);
>
> lstComputerExceptions.setSelectedIndex(index);
> lstComputerExceptions.ensureIndexIsVisible(index);
> }
Did you before hand do this?
tempListModel = new DefaultListModel();
tempListModel.addElement("First");
tempListModel.addElement("Second");
tempListModel.addElement("Third");
lstComputerExceptions = new JList(templistModel);
Peter,
|
|
0
|
|
|
|
Reply
|
TheBigPJ
|
2/28/2008 4:55:57 PM
|
|
On Feb 28, 3:49 pm, christopher_bo...@yahoo.co.uk wrote:
> On 28 Feb, 14:47, TheBigPJ <TheBi...@gmail.com> wrote:
>
> > I think this link will satisfy your needs and maybe more.
>
> >http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
>
> Hi all. Thanks for the replies. I have had a look at the website
> mentioned above by TheBigPJ and have entered the following the code
> into my program:
> int index = lstComputerExceptions.getSelectedIndex();
> lstComputerExceptions.remove(index);
>
> lstComputerExceptions.setSelectedIndex(index);
> lstComputerExceptions.ensureIndexIsVisible(index);
> }
>
> However when I run it always comes up with the following error
> message:
> ception occurred during event dispatching:
> java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
<snip>
I suspect that the error refers to line of code
= lstComputerExceptions.setSelectedIndex(index);
If you look at the line immediately preceding that one you might see
what may be causing the error...
|
|
0
|
|
|
|
Reply
|
GArlington
|
2/29/2008 11:53:56 AM
|
|
|
4 Replies
352 Views
(page loaded in 0.109 seconds)
Similiar Articles: Removing an item from a Jlist - comp.lang.java.helpHi all, I m currently developing a java application where information from a file is populated into a JList. The user should be able to select an item from the JList ... NetBeans jList Add/Clear Items - comp.lang.java.guiRemoving an item from a Jlist - comp.lang.java.help Removing jdk depot - comp.sys.hp.hpux Removing an item from a Jlist - comp.lang.java.help... Clear Items ... Help with JList and JComboBox - comp.lang.java.guiRemoving an item from a Jlist - comp.lang.java.help Help with JList and JComboBox - comp.lang.java.gui Removing an item from a Jlist - comp.lang.java.help Help with JList ... actionPerformed programmatically - comp.lang.java.guiRemoving an item from a Jlist - comp.lang.java.help... java: 191) at remoteshutdown.ExceptionsList_btnDelete_actionAdapter.actionPerformed ... How to programmatically ... How to programmatically select a list in JList? - comp.lang.java ...Removing an item from a Jlist - comp.lang.java.help How to programmatically select a list in JList? - comp.lang.java ... Hi, I am using JList component and I add a vector ... Surprising pop_head performance compared to push_heap - comp.lang ...Removing an item from a Jlist - comp.lang.java.help Surprising pop_head performance compared to push_heap - comp.lang ... > (or conversely, that it is faster to remove ... Thread-safe Queue on Win32 - comp.programming.threadsRemoving an item from a Jlist - comp.lang.java.help Thread-safe Queue on Win32 - comp.programming.threads How to make a STL queue thread safe across platform (both Win32 ... disable jcombobox item - comp.lang.java.guiHi all, I would like to disable an item in a JComboBox. By "disable" I mean to ... import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList ... remove all nodes from a JTree? - comp.lang.java.gui... that has been selected in a JList. Now the problem is, that if I remove all ... my list, and then again the first item ... mount point - comp.unix.solaris... how to remove a ... Bottom-up heap construction in O(n) - comp.lang.c++.moderated ...... function //it is a recursive funtion { } Although I got an algorithm for this, but I couldn't implement it properly, the algorithm is something like: remove an item ... Adding and Removing an Item in a JList Component | Example DepotSir i have useing a JList componenet to a form , in that when i add a item in constructor the item will add, when we use a mithod to do that and call Listener method ... Removing items from a JList??: jlist, remove, item, fromHi there! I have the following code that creates a JList from a textfile. However i am trying to delete an item, but I keep getting a nullpointer exception ... 7/15/2012 5:54:24 PM
|
|
|
|
|
|
|
|
|