21
LINES
JavaX fragment (include)
1 | import javax.swing.plaf.basic.BasicSliderUI;
|
2 |
|
3 | static void fixSliderScrolling(final JSlider s) {
|
4 | MouseListener[] listeners = s.getMouseListeners();
|
5 | for (MouseListener l : listeners)
|
6 | s.removeMouseListener(l); // remove UI-installed TrackListener
|
7 | final BasicSliderUI ui = (BasicSliderUI) s.getUI();
|
8 | BasicSliderUI.TrackListener tl = ui.new TrackListener() {
|
9 | // this is where we jump to absolute value of click
|
10 | @Override public void mouseClicked(MouseEvent e) {
|
11 | Point p = e.getPoint();
|
12 | int value = ui.valueForXPosition(p.x);
|
13 | s.setValue(value);
|
14 | }
|
15 | // disable check that will invoke scrollDueToClickInTrack
|
16 | @Override public boolean shouldScroll(int dir) {
|
17 | return false;
|
18 | }
|
19 | };
|
20 | s.addMouseListener(tl);
|
21 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
ID |
Author/Program |
Comment |
Date |
1246 | stefan | Doesn't work with Substance (not tried with standard Swing) | 2016-07-24 21:55:19 |
add comment
Snippet ID: |
#1003646 |
Snippet name: |
fixSliderScrolling |
Eternal ID of this version: |
#1003646/1 |
Text MD5: |
bf4235ca35067f830827ffa350f83b11 |
Author: |
stefan |
Category: |
javax |
Type: |
JavaX fragment (include) |
Public (visible to everyone): |
Yes |
Archived (hidden from active list): |
No |
Created/modified: |
2016-07-24 21:54:31 |
Source code size: |
784 bytes / 21 lines |
Pitched / IR pitched: |
No / No |
Views / Downloads: |
825 / 797 |
Referenced in: |
[show references] |