diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java index 3a8b7a99f458c..ac8d1cb5bb37d 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -124,8 +124,6 @@ public class BasicScrollBarUI protected ModelListener modelListener; /** KeyboardFocusListener */ protected KeyboardFocusListener keyboardFocusListener; - /** KeyboardFocusManager */ - protected KeyboardFocusManager keyboardFocusManager; /** Thumb rectangle */ protected Rectangle thumbRect; @@ -360,7 +358,6 @@ protected void installListeners(){ buttonListener = createArrowButtonListener(); modelListener = createModelListener(); propertyChangeListener = createPropertyChangeListener(); - keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); keyboardFocusListener = createKeyboardFocusListener(); scrollbar.addMouseListener(trackListener); @@ -368,7 +365,8 @@ protected void installListeners(){ scrollbar.getModel().addChangeListener(modelListener); scrollbar.addPropertyChangeListener(propertyChangeListener); scrollbar.addFocusListener(getHandler()); - keyboardFocusManager.addPropertyChangeListener(keyboardFocusListener); + KeyboardFocusManager.getCurrentKeyboardFocusManager() + .addPropertyChangeListener(keyboardFocusListener); if (incrButton != null) { incrButton.addMouseListener(buttonListener); @@ -450,8 +448,8 @@ protected void uninstallListeners() { incrButton.removeMouseListener(buttonListener); } - keyboardFocusManager.removePropertyChangeListener(keyboardFocusListener); - keyboardFocusManager = null; + KeyboardFocusManager.getCurrentKeyboardFocusManager() + .removePropertyChangeListener(keyboardFocusListener); scrollbar.getModel().removeChangeListener(modelListener); scrollbar.removeMouseListener(trackListener); scrollbar.removeMouseMotionListener(trackListener); @@ -1236,6 +1234,10 @@ public void propertyChange(PropertyChangeEvent e) { // Stop scrolling if no longer focus owner if (e.getNewValue() == null && scrollTimer.isRunning()) { scrollTimer.stop(); + if (buttonListener.handledEvent) { + buttonListener.handledEvent = false; + } + scrollbar.setValueIsAdjusting(false); } } } diff --git a/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java b/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java index 5ec988feb1403..a337e10e7e8f2 100644 --- a/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java +++ b/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java @@ -21,13 +21,9 @@ * questions. */ -import java.awt.AWTException; -import java.lang.reflect.InvocationTargetException; - import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; /* * @test @@ -53,10 +49,7 @@ public class JComboBoxScrollFocusTest { passes, otherwise it fails. """; - public static void main(String[] args) throws - UnsupportedLookAndFeelException, ClassNotFoundException, - InstantiationException, IllegalAccessException, AWTException, - InterruptedException, InvocationTargetException { + public static void main(String[] args) throws Exception { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); PassFailJFrame .builder() @@ -72,7 +65,7 @@ public static void main(String[] args) throws private static JFrame createAndShowGUI() { JFrame frame = new JFrame("JComboBoxScrollFocusTest Test Frame"); JComboBox combobox = new JComboBox(); - for (int i = 0; i< 100; i ++) { + for (int i = 0; i < 100; i ++) { combobox.addItem(String.valueOf(i)); } frame.add(combobox); @@ -82,4 +75,4 @@ private static JFrame createAndShowGUI() { frame.setVisible(true); return frame; } -} \ No newline at end of file +}