@ca_schaefer: "I sometimes see the following exception:
java.lang.IllegalArgumentException: Invalid location
 at javax.swing.text.JTextComponent.getSelectedText(Unknown Source)
 at 
javax.swing.text.JTextComponent$AccessibleJTextComponent.getSelectedText(Unknown 
Source)
 at 
javax.swing.text.JTextComponent$AccessibleJTextComponent.caretUpdate(Unknown 
Source)
 at javax.swing.text.JTextComponent.fireCaretUpdate(Unknown Source)
 at javax.swing.text.JTextComponent$MutableCaretEvent.fire(Unknown Source)
 at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(Unknown 
Source)
 at javax.swing.text.DefaultCaret.fireStateChanged(Unknown Source)
 at javax.swing.text.DefaultCaret.changeCaretPosition(Unknown Source)
 at javax.swing.text.DefaultCaret.handleMoveDot(Unknown Source)
 at javax.swing.text.DefaultCaret.moveDot(Unknown Source)
 at javax.swing.text.DefaultCaret$UpdateHandler.insertUpdate(Unknown Source)
 at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source)
 at javax.swing.text.AbstractDocument.handleInsertString(Unknown Source)
 at javax.swing.text.AbstractDocument.insertString(Unknown Source)
 at javax.swing.text.PlainDocument.insertString(Unknown Source)
 at javax.swing.text.AbstractDocument.replace(Unknown Source)
 at javax.swing.text.JTextComponent.setText(Unknown Source)
 at javax.swing.plaf.metal.MetalComboBoxEditor$1.setText(Unknown Source)
 at javax.swing.plaf.basic.BasicComboBoxEditor.setItem(Unknown Source)
 at javax.swing.JComboBox.configureEditor(Unknown Source)
 at 
javax.swing.plaf.basic.BasicComboBoxUI$ListDataHandler.contentsChanged(Unknown 
Source)
 at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
 at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
 at javax.swing.JComboBox.setSelectedItem(Unknown Source)
 at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
when i call setSelectedIndex(0) on a combobox filled with some strings.
Does somebody know what it means ?
Carsten "
    @nospam: "<quote>
/ ...
Yes, it means there is no item with an index of 0. Solution: test for the
presence of this indexed item before trying to select it.
Remember, in programming, zero is a valid number just like one or two, and
if you specify an index of zero, there must be an index-zero item present,
or you will get an error.
Paul Lutus
<url>"
    @ca_schaefer: "<quote>
I don't understand your answer.
I thought setSelectedIndex(0) selects the first item in a JComboBox.
If there are no items in the combobox i get: setSelectedIndex: 0 out of 
bounds
How do i test the presence of the item at index 0 ?
Carsten "
    @ca_schaefer: "<quote>
This tests if there are items in the combobox.
As i wrote i get 'java.lang.IllegalArgumentException: Invalid location'
and not 'setSelectedIndex: 0 out of bounds'
This would happen if there are no items in the combobox.
Or am i wrong ?
Carsten"
    @nospam: "Carsten Sch=E4fer schrieb:
<quote>
=20
probably like this:
   if (comboBox.getItemCount() > 0)
     comboBox.setSelectedIndex(0);
=20
Thomas<dot>Fritsch<squiggle>ops<dot>de"
    @nospam: "/ ...
<quote>
Why not take the suggestion and test for the presence of an item at index
zero? See if this solves the problem.
Also, it is possible to put an "object" equal to null at index zero. This
might result in the error message you saw. We really cannot say without
seeing your code.
Paul Lutus
<url>"
    @nospam: "Carsten Sch=E4fer schrieb:
<quote>
Hmpf, you are right!
After re-reading the exception stack trace in your original post I saw:
The exception did *not* occur because 0 were an illegal combobox item=20
index, but because there was an illegal *character* index in the string=20
when JTextComponent#getSelectedText fiddled around with selected text=20
and caret position.
=3D> it may be a bug of yours or of Sun...
Consider posting a stripped down version of your source.
=20
Thomas<dot>Fritsch<squiggle>ops<dot>de"
    @kala: "<quote>
It would solve the problem only if it were an ArrayOutOfBoundsException 
that he got.
If you looked at the stacktrace carefully, you would notice that the 
exception was generated when swing tried to update the Caret in the 
textbox portion - so there is no point trying to solve a non-existent issue.
To the OP : Most errors of this type occur if the thread safety rules of 
the swing framework are not followed. So check your code to see if you 
are making this call from some thread other than the EDT. (it certainly 
appears to be that if what you posted is the *complete* stacktrace. 
Stacktraces originating from code running in the EDT should have some 
event queue processing code as the last lines)
BK"
{'source': 'USENET', 'other_information': '{"reply_count": 7, "forum_name": "comp.lang.java.gui.20150104.mbox"}', 'file': 'data/output/usenet-comp.lang.parquet'}