Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Jlist deselect

Options
  • 11-02-2003 5:04pm
    #1
    Registered Users Posts: 3,958 ✭✭✭


    Does someone know how i could deselect all selected indexes in a jlist, everytime i try and add to the jlist while there is something selected theres a mad error.
    id appreciate any help as this has been annoying me for hours now..


Comments

  • Registered Users Posts: 6,240 ✭✭✭hussey


    Originally posted by Chad ghostal
    Does someone know how i could deselect all selected indexes in a jlist, everytime i try and add to the jlist while there is something selected theres a mad error.
    id appreciate any help as this has been annoying me for hours now..

    what is the mad error??

    just give use the first few lines or so


  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    this is the whole thing..jic..

    applets name is PhonCoApplet

    i add the phoneCo's name (textbox.gettext()) to a vector then put them into the list using
    list.setlistdata

    there is only ever an error when the list has an item selected prior to addition of a new object


    Exception occurred during event dispatching:

    java.lang.ArrayIndexOutOfBoundsException: 1 >= 0

    at java.util.Vector.setElementAt(Vector.java:482)

    at PhoneCoApplet.addToList(PhoneCoApplet.java:126)

    at PhoneCoApplet.actionPerformed(PhoneCoApplet.java:105)

    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)

    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)

    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)

    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)

    at javax.swing.plaf.basic.BasicRootPaneUI$DefaultAction.actionPerformed(BasicRootPaneUI.java:156)

    at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1384)

    at javax.swing.JComponent.processKeyBinding(JComponent.java:2078)

    at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:252)

    at javax.swing.KeyboardManager.fireKeyboardAction(KeyboardManager.java:205)

    at javax.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:2145)

    at javax.swing.JComponent.processKeyBindings(JComponent.java:2138)

    at javax.swing.JComponent.processKeyEvent(JComponent.java:2045)

    at java.awt.Component.processEvent(Component.java:3553)

    at java.awt.Container.processEvent(Container.java:1164)

    at java.awt.Component.dispatchEventImpl(Component.java:2593)

    at java.awt.Container.dispatchEventImpl(Container.java:1213)

    at java.awt.Component.dispatchEvent(Component.java:2497)

    at java.awt.LightweightDispatcher.processKeyEvent(Container.java:2155)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2135)

    at java.awt.Container.dispatchEventImpl(Container.java:1200)

    at java.awt.Component.dispatchEvent(Component.java:2497)

    at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)

    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)

    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)


  • Registered Users Posts: 6,240 ✭✭✭hussey


    is there any chance of putting link up to code??

    and how do you define the array?? or vector??

    what demensions??

    java.util.Vector.setElementAt(Vector.java:482)

    What are the Parameters???
    obj - what the component is to be set to.
    index - the specified index.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Without seeing the code I can only guess on what you said.
    there is only ever an error when the list has an item selected prior to addition of a new object

    I take it that you are selecting an item on the list, then clearing the list and trying to select the item again (which obviously is no longer there?). Reset the selection beforehand?


  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    here is all the code relating to the list
    i would put all the code up but i have nowhere to put it ..
    this is all in the same class


    init()
    {
    nameVector = new Vector(5);
    list =new JList();
    list.setSelectionMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    }


    public void actionPerformed(ActionEvent evt)
    {
    ///rightPane is just another panel,saveInput a button on panel
    if(evt.getSource() == rightPane.saveInput)
    {


    // getTelcoName just gets the name using getText()
    addToList(new String(rightPane.getTelcoName()));

    rightPane.resetAddNew();
    }
    }


    public void addToList(Object o)
    {
    nameVector.addElement(o);

    list.setListData(nameVector);
    }



    //this method just displays the info of the phoneco and takes off a graph if its there..
    //i dont know what the getvalueIsAdjusting does but i dont think it has any effect
    //when i removed it the same thing happened again

    public class ListListener implements ListSelectionListener/*ListSelectionListener*/
    {
    public void valueChanged(ListSelectionEvent evt)
    {
    if(evt.getValueIsAdjusting())
    return;

    int index = list.getSelectedIndex();


    if(splitPane.getRightComponent() == graphHolder)
    {
    removeGraph();
    }

    rightPane.displaydetails((Telco)objectVector.get(index));

    }


    }


  • Advertisement
  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    this occurs when i have one or more things in the list,
    if i select any of the items in the list and i cannot deselect all of them.

    Then when i go to add a new phonecO the compiler gives out sh1t to me. .


  • Registered Users Posts: 6,240 ✭✭✭hussey


    you can upload the code to boards.ie

    you can zip the code (.java and .html, not .class)
    and use the attach file function down below


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Use of the [code] vb Code element might help readability here.


  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    heres the code...
    im writing a mouse listener but that doesnt work so ignore it..


  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    im not sure why but it works perfectly now..it deselects and everything.. thanks anyway..
    now all i have to do if figure out why>.


  • Advertisement
  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Originally posted by Chad ghostal
    im not sure why but it works perfectly now

    Heisenbug.


Advertisement