-
Bug
-
Resolution: Fixed
-
P2
-
0.9
-
None
-
0.9internal
-
x86
-
windows_95
-
Verified
Exception occurred during event dispatching:
java.lang.ClassCastException:
at com.sun.java.swing.JListSelectionModel$EventMulticaster.add(JListSele
ctionModel.java:70)
at com.sun.java.swing.JListSelectionModel.addListSelectionListener(JList
SelectionModel.java:81)
at JavaHelp.TOCPanel.<init>(TOCPanel.java:74)
at JavaHelp.HelpDialog.<init>(HelpDialog.java:202)
at HelpDialogTest$1.actionPerformed(HelpDialogTest.java:39)
at com.sun.java.swing.JButton$3.actionPerformed(JButton.java:552)
at com.sun.java.swing.JButton$Model.setPressed(JButton.java:734)
at com.sun.java.swing.basic.BasicButtonUI$Listener.mouseReleased(BasicBu
ttonUI.java:352)
at java.awt.Component.processMouseEvent(Component.java:1898)
at java.awt.Component.processEvent(Component.java:1775)
at java.awt.Container.processEvent(Container.java:792)
at java.awt.Component.dispatchEventImpl(Component.java:1453)
at java.awt.Container.dispatchEventImpl(Container.java:837)
at java.awt.Component.dispatchEvent(Component.java:1393)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1411
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1329)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1264)
at java.awt.Container.dispatchEventImpl(Container.java:824)
at java.awt.Window.dispatchEventImpl(Window.java:401)
at java.awt.Component.dispatchEvent(Component.java:1393)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)
Code -----
topNode = new TreeNode ();
populateTree();
tree = new JTree (topNode);
ListSelectionModel lsm = tree.getSelectionModel();
lsm.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
System.out.println ("firstIndex=" + e.getFirstIndex());
System.out.println ("lastIndex=" + e.getLastIndex());
}
});
This report from Willie Walker
From: "Willie Walker" <###@###.###>
To: <###@###.###>
Subject: Possible bug in JListSelectionModel
Date: Mon, 16 Jun 1997 12:26:58 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_01BC7A50.95DD1E40
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Greetings:
I think the JListSelectionModel might be broken when it comes to adding
selection listeners. If I take a class that implements ListSelectionListener
and try to add it as a listener using addListSelectionListener, I get
a cast exception from java.awt.AWTEventMulticaster at run time:
wwalker@soslow> java ListBoxTest
Default UI factory not set, using BasicFactory
java.lang.ClassCastException: java.awt.AWTEventMulticaster
at com.sun.java.swing.JListSelectionModel$EventMulticaster.add(JListSelectionModel.java:70)
at com.sun.java.swing.JListSelectionModel.addListSelectionListener(JListSelectionModel.java:81)
at ListBoxTest.main(ListBoxTest.java:58)
^Cwwalker@soslow> bugtraq
Attached is a modified ListBoxTest.java that demonstrates the problem.
I currently don't have access to bugtraq right now (still reeling from
new employee syndrome). If that is a more appropriate place to post
this possible bug, please let me know.
Thanks!
Will
------=_NextPart_000_01BC7A50.95DD1E40
Content-Type: application/octet-stream; name="ListBoxTest.java"
Content-Transfer-Encoding: quoted-printable
Content-Description: ListBoxTest.java (Java Source File)
Content-Disposition: attachment; filename="ListBoxTest.java"
=0A=
import java.awt.*;=0A=
import java.awt.event.*;=0A=
import com.sun.java.swing.*;=0A=
import java.util.*;=0A=
=0A=
class TestCellRenderer extends JLabel implements ListCellRenderer=0A=
{=0A=
JListBox listbox;=0A=
Glyph gromit =3D new ImageGlyph("images/gromit.gif");=0A=
Glyph wallace =3D new ImageGlyph("images/wal.gif");=0A=
=0A=
TestCellRenderer(JListBox listbox) {=0A=
this.listbox =3D listbox;=0A=
}=0A=
=0A=
public void setListCellValue(Object value, int index) {=0A=
setText(value.toString());=0A=
setGlyph((listbox.isSelectedIndex(index)) ? gromit : wallace);=0A=
}=0A=
=0A=
public Component getListCellComponent() {=0A=
return this;=0A=
}=0A=
}=0A=
=0A=
class MyListSelectionListener implements EventListener, =
ListSelectionListener {=0A=
public void valueChanged(ListSelectionEvent e) {=0A=
System.out.println("MySelectionListener: valueChanged.");=0A=
}=0A=
}=0A=
=0A=
=0A=
public class ListBoxTest=0A=
{=0A=
public static void main(String[] args)=0A=
{=0A=
ListDataModel model =3D new JListDataModelAdapter() {=0A=
public int getSize() { return 25; }=0A=
public Object getElementAt(int i) { return "Hello, I'm row " + i; =
}=0A=
};=0A=
=0A=
final JListBox listbox =3D new JListBox(model);=0A=
listbox.setCellRenderer(new TestCellRenderer(listbox));=0A=
listbox.setNCellsVisible(6);=0A=
=0A=
MouseListener ml =3D new MouseAdapter() {=0A=
public void mousePressed(MouseEvent x) {=0A=
int i0 =3D listbox.getFirstVisibleIndex();=0A=
int i1 =3D listbox.getLastVisibleIndex();=0A=
System.out.println("firstVisibleIndex: " + i0);=0A=
System.out.println("lastVisibleIndex: " + i1);=0A=
// listbox.ensureIndexIsVisible(12);=0A=
}=0A=
};=0A=
listbox.addMouseListener(ml);=0A=
=0A=
listbox.getSelectionModel().addListSelectionListener(new =
MyListSelectionListener());=0A=
=0A=
=0A=
JPanel p =3D new JPanel(true) {=0A=
public Insets getInsets() { return new Insets(4, 4, 4, 4); }=0A=
};=0A=
p.setLayout(new GridLayout(1,1));=0A=
p.add(listbox);=0A=
=0A=
WindowListener l =3D new WindowAdapter() {=0A=
public void windowClosing(WindowEvent e) {System.exit(0);}=0A=
};=0A=
=0A=
JFrame f =3D new JFrame("ListBox");=0A=
f.addWindowListener(l); =0A=
f.add(p);=0A=
f.pack();=0A=
f.show(); =0A=
}=0A=
}=0A=
------=_NextPart_000_01BC7A50.95DD1E40--
java.lang.ClassCastException:
at com.sun.java.swing.JListSelectionModel$EventMulticaster.add(JListSele
ctionModel.java:70)
at com.sun.java.swing.JListSelectionModel.addListSelectionListener(JList
SelectionModel.java:81)
at JavaHelp.TOCPanel.<init>(TOCPanel.java:74)
at JavaHelp.HelpDialog.<init>(HelpDialog.java:202)
at HelpDialogTest$1.actionPerformed(HelpDialogTest.java:39)
at com.sun.java.swing.JButton$3.actionPerformed(JButton.java:552)
at com.sun.java.swing.JButton$Model.setPressed(JButton.java:734)
at com.sun.java.swing.basic.BasicButtonUI$Listener.mouseReleased(BasicBu
ttonUI.java:352)
at java.awt.Component.processMouseEvent(Component.java:1898)
at java.awt.Component.processEvent(Component.java:1775)
at java.awt.Container.processEvent(Container.java:792)
at java.awt.Component.dispatchEventImpl(Component.java:1453)
at java.awt.Container.dispatchEventImpl(Container.java:837)
at java.awt.Component.dispatchEvent(Component.java:1393)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1411
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1329)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1264)
at java.awt.Container.dispatchEventImpl(Container.java:824)
at java.awt.Window.dispatchEventImpl(Window.java:401)
at java.awt.Component.dispatchEvent(Component.java:1393)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)
Code -----
topNode = new TreeNode ();
populateTree();
tree = new JTree (topNode);
ListSelectionModel lsm = tree.getSelectionModel();
lsm.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
System.out.println ("firstIndex=" + e.getFirstIndex());
System.out.println ("lastIndex=" + e.getLastIndex());
}
});
This report from Willie Walker
From: "Willie Walker" <###@###.###>
To: <###@###.###>
Subject: Possible bug in JListSelectionModel
Date: Mon, 16 Jun 1997 12:26:58 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_01BC7A50.95DD1E40
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Greetings:
I think the JListSelectionModel might be broken when it comes to adding
selection listeners. If I take a class that implements ListSelectionListener
and try to add it as a listener using addListSelectionListener, I get
a cast exception from java.awt.AWTEventMulticaster at run time:
wwalker@soslow> java ListBoxTest
Default UI factory not set, using BasicFactory
java.lang.ClassCastException: java.awt.AWTEventMulticaster
at com.sun.java.swing.JListSelectionModel$EventMulticaster.add(JListSelectionModel.java:70)
at com.sun.java.swing.JListSelectionModel.addListSelectionListener(JListSelectionModel.java:81)
at ListBoxTest.main(ListBoxTest.java:58)
^Cwwalker@soslow> bugtraq
Attached is a modified ListBoxTest.java that demonstrates the problem.
I currently don't have access to bugtraq right now (still reeling from
new employee syndrome). If that is a more appropriate place to post
this possible bug, please let me know.
Thanks!
Will
------=_NextPart_000_01BC7A50.95DD1E40
Content-Type: application/octet-stream; name="ListBoxTest.java"
Content-Transfer-Encoding: quoted-printable
Content-Description: ListBoxTest.java (Java Source File)
Content-Disposition: attachment; filename="ListBoxTest.java"
=0A=
import java.awt.*;=0A=
import java.awt.event.*;=0A=
import com.sun.java.swing.*;=0A=
import java.util.*;=0A=
=0A=
class TestCellRenderer extends JLabel implements ListCellRenderer=0A=
{=0A=
JListBox listbox;=0A=
Glyph gromit =3D new ImageGlyph("images/gromit.gif");=0A=
Glyph wallace =3D new ImageGlyph("images/wal.gif");=0A=
=0A=
TestCellRenderer(JListBox listbox) {=0A=
this.listbox =3D listbox;=0A=
}=0A=
=0A=
public void setListCellValue(Object value, int index) {=0A=
setText(value.toString());=0A=
setGlyph((listbox.isSelectedIndex(index)) ? gromit : wallace);=0A=
}=0A=
=0A=
public Component getListCellComponent() {=0A=
return this;=0A=
}=0A=
}=0A=
=0A=
class MyListSelectionListener implements EventListener, =
ListSelectionListener {=0A=
public void valueChanged(ListSelectionEvent e) {=0A=
System.out.println("MySelectionListener: valueChanged.");=0A=
}=0A=
}=0A=
=0A=
=0A=
public class ListBoxTest=0A=
{=0A=
public static void main(String[] args)=0A=
{=0A=
ListDataModel model =3D new JListDataModelAdapter() {=0A=
public int getSize() { return 25; }=0A=
public Object getElementAt(int i) { return "Hello, I'm row " + i; =
}=0A=
};=0A=
=0A=
final JListBox listbox =3D new JListBox(model);=0A=
listbox.setCellRenderer(new TestCellRenderer(listbox));=0A=
listbox.setNCellsVisible(6);=0A=
=0A=
MouseListener ml =3D new MouseAdapter() {=0A=
public void mousePressed(MouseEvent x) {=0A=
int i0 =3D listbox.getFirstVisibleIndex();=0A=
int i1 =3D listbox.getLastVisibleIndex();=0A=
System.out.println("firstVisibleIndex: " + i0);=0A=
System.out.println("lastVisibleIndex: " + i1);=0A=
// listbox.ensureIndexIsVisible(12);=0A=
}=0A=
};=0A=
listbox.addMouseListener(ml);=0A=
=0A=
listbox.getSelectionModel().addListSelectionListener(new =
MyListSelectionListener());=0A=
=0A=
=0A=
JPanel p =3D new JPanel(true) {=0A=
public Insets getInsets() { return new Insets(4, 4, 4, 4); }=0A=
};=0A=
p.setLayout(new GridLayout(1,1));=0A=
p.add(listbox);=0A=
=0A=
WindowListener l =3D new WindowAdapter() {=0A=
public void windowClosing(WindowEvent e) {System.exit(0);}=0A=
};=0A=
=0A=
JFrame f =3D new JFrame("ListBox");=0A=
f.addWindowListener(l); =0A=
f.add(p);=0A=
f.pack();=0A=
f.show(); =0A=
}=0A=
}=0A=
------=_NextPart_000_01BC7A50.95DD1E40--