Skip to main content

Unable to scroll in JXLayer with an unlocked LockableUI

3 replies [Last post]
tiho_me
Offline
Joined: 2009-08-16
Points: 0

Hi,

I way playing with the LockableUIDemo and found this ineresting behaviour:

If you have a JXLayer and put it in a JScrollPane; mouse-wheel scroll actions are blocked; whereas if you have a JScrollPane and put it in a JXLayer, mouse scrolling works.

Can anyone help me with why this occurs and if there is a way to get scrolling working with this 'JXLayer within a JScrollPane' arrangement?

See my example code below. If you run it, you will notice that mouse scrolling does not work in the main panel - it does work when the mouse is over the scrollbar, however.

public LockableScrollpaneDemo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this arrangement does not scroll (ie. JXLayer within a ScrollPane)
JPanel p = new JPanel();
p.add(new JLabel("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong Label:"));

JXLayer layer = new JXLayer(p);
layer.setUI(new LockableUI());

add(new JScrollPane(layer));

setSize(300, 200);
setLocationRelativeTo(null);
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new LockableScrollpaneDemo().setVisible(true);
}
});
}
}

Note that if you change it so that the JScrollPane is within the layer (see below), then scrolling works.

JXLayer layer = new JXLayer(new JScrollPane(p));
layer.setUI(new LockableUI());
add(layer);

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tiho_me
Offline
Joined: 2009-08-16
Points: 0

Thanks Alex!

That certainly fixed my issue.
I really like the work you guys are doing, btw. Much appreciated.

Tiho

alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Tiho

You are welcome

alexp

alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello tiho_me

You've found a little bug in the LockalbleUI!
To workaround it please override the getLayerEventMask() method like this:

[code]
layer.setUI(new LockableUI() {
public long getLayerEventMask() {
return 0;
}
});
[/code]

Thanks
alexp