Mouse wheel not scrolling in JDialog but working in JFrame
- by Iulian Serbanoiu
Hello,
I'm facing a frustrating issue. I have an application where the scroll wheel doesn't work in a JDialog window (but works in a JFrame).
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)
LATER EDIT:
The problem persists with jre/jdk_1.6.0_10, 1.6.0_16 also
LATER EDIT 2:
Back home, tested on linux (Ubuntu - lucid/lynx) - both with openjdk and sun-java from distribution repo and it works (I used the .class file compiled on Windows) !!! - so I believe I'm facing a JRE bug that happens on some Windows configurations.