Skip to main content

ArrayIndexOutOfBoundsException in PatternHighlighter

4 replies [Last post]
rturnbull
Offline
Joined: 2005-08-27

When applying a PatternHighlighter to a JXTable that affects the whole row, I get an exception if I hide the column being tested, using the Column Header popup control.
No problem if I rearrange the columns.
I include a partial stacktrace

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(ArrayList.java:324)
at org.jdesktop.binding.metadata.DefaultMetaDataProvider.getFieldName(DefaultMetaDataProvider.java:64)
at org.jdesktop.binding.swingx.adapter.DataModelToTableModelAdapter.getFieldName(DataModelToTableModelAdapter.java:106)
at org.jdesktop.binding.swingx.adapter.DataModelToTableModelAdapter.getValueAt(DataModelToTableModelAdapter.java:101)
at org.jdesktop.swingx.JXTable.getValueAt(JXTable.java:853)
at org.jdesktop.swingx.JXTable$TableAdapter.getFilteredValueAt(JXTable.java:1918)
at org.jdesktop.swingx.decorator.PatternHighlighter.test(PatternHighlighter.java:110)

Any suggestions?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kleopatra

jdnc-interest@javadesktop.org wrote:
> When applying a PatternHighlighter to a JXTable that affects
> the whole row, I get an exception if I hide the column being tested,
> using the Column Header popup control.

Looks like you hit a bug in tableComponentAdapter.getFilteredValue(): it
converts the given model column index to view column index without
expecting a -1 as a result (this happens if the column is currently
invisible). I think it should be solved at that point (maybe using your
workaround, will have to think about it).

Could you please file an issue?

Thanks for your constructive feedback!
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

rturnbull
Offline
Joined: 2005-08-27

[i]>Looks like you hit a bug in tableComponentAdapter.getFilteredValue(): it
converts the given model column index to view column index without
expecting a -1 as a result (this happens if the column is currently
invisible). I think it should be solved at that point (maybe using your
workaround, will have to think about it).[/i]

I have logged issue 180 in swingx

After sleeping on it, I don't think you should use my workaround.
I agree it should be fixed at tableComponentAdapter.getFilteredValue(). It should be fairly straight forward to change that method to convert the row to model coordinates and retrieve value, rather than changing the column to view coordinates as at present.
This solves the real problem for all time rather than avoiding it in one particular instance as I have done.

kleopatra
Offline
Joined: 2003-06-11

Hi Ray,

>
> I have logged issue 180 in swingx
>
> After sleeping on it, I don't think you should use my
> workaround.
> I agree it should be fixed at
> tableComponentAdapter.getFilteredValue(). It should
> be fairly straight forward to change that method to
> convert the row to model coordinates and retrieve
> value, rather than changing the column to view
> coordinates as at present.

that's what I meant (having done a bad job in making myself clear :-)

Thanks!
Jeanette

rturnbull
Offline
Joined: 2005-08-27

Further to the above, I subclassed PatternHighlighter and replaced the test() method with the following, and it worked for me.

protected boolean test(ComponentAdapter adapter) {
if (pattern == null) {
return false;
}
if (!adapter.isTestable(testColumn)) return false;

[b]Component comp = adapter.getComponent();
Object value = null;
if (comp instanceof JXTable) {
int modelRow = ((JXTable)comp).convertRowIndexToModel(adapter.row);
value = adapter.getValueAt(modelRow, testColumn);
} else {[/b]
value = adapter.getFilteredValueAt(adapter.row, testColumn);
[b]}[/b]

if (value == null) {
return false;
}
else {
boolean matches = pattern.matcher(value.toString()).find();
return matches;
}
}