Mouse wheel not scrolling in JDialog
Posted
by Iulian Serbanoiu
on Stack Overflow
See other posts from Stack Overflow
or by Iulian Serbanoiu
Published on 2010-03-17T09:23:27Z
Indexed on
2010/03/17
10:01 UTC
Read the original article
Hit count: 456
Hello,
I'm facing a frustrating issue. I have an application where the scroll wheel doesn't work in a JDialog class.
Here's the code:
import javax.swing.*;
import java.awt.event.*;
public class Failtest extends JFrame {
public static void main(String[] args) {
new Failtest();
}
public Failtest() {
super();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("FRAME");
JScrollPane sp1 = new JScrollPane(getNewList());
add(sp1);
setSize(150, 150);
setVisible(true);
JDialog d = new JDialog(this, false);// NOT WORKING
//JDialog d = new JDialog((JFrame)null, false); // NOT WORKING
//JDialog d = new JDialog((JDialog)null, false);// WORKING - WHY?
d.setTitle("DIALOG");
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
JScrollPane sp = new JScrollPane(getNewList());
d.add(sp);
d.setSize(150, 150);
d.setVisible(true);
}
public JList getNewList() {
String objs[] = new String[30];
for(int i=0; i<objs.length; i++) {
objs[i] = "Item "+i;
}
JList l = new JList(objs);
return l;
}
}
I found a solution which is present as a comment in the java code - the constructor receiving a (JDialog)null parameter.
Can someone enlighten me? My opinion is that this is a java bug.
Tested on Windows XP-SP3 with 1 JDK and 2 JREs:
D:\Program Files\Java\jdk1.6.0_17\bin>javac -version
javac 1.6.0_17
D:\Program Files\Java\jdk1.6.0_17\bin>java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
D:\Program Files\Java\jdk1.6.0_17\bin>cd ..
D:\Program Files\Java\jdk1.6.0_17>java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
Thank you in advance,
Iulian Serbanoiu
PS: The problem is not new - the code is taken from a forum (here) where this problem was also mentioned - but no solutions to it (yet)
© Stack Overflow or respective owner