Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonGuy committed Sep 5, 2024
1 parent 0cc3caf commit 312c484
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ public class BasicScrollBarUI
protected ModelListener modelListener;
/** KeyboardFocusListener */
protected KeyboardFocusListener keyboardFocusListener;
/** KeyboardFocusManager */
protected KeyboardFocusManager keyboardFocusManager;

/** Thumb rectangle */
protected Rectangle thumbRect;
Expand Down Expand Up @@ -360,15 +358,15 @@ protected void installListeners(){
buttonListener = createArrowButtonListener();
modelListener = createModelListener();
propertyChangeListener = createPropertyChangeListener();
keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
keyboardFocusListener = createKeyboardFocusListener();

scrollbar.addMouseListener(trackListener);
scrollbar.addMouseMotionListener(trackListener);
scrollbar.getModel().addChangeListener(modelListener);
scrollbar.addPropertyChangeListener(propertyChangeListener);
scrollbar.addFocusListener(getHandler());
keyboardFocusManager.addPropertyChangeListener(keyboardFocusListener);
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener(keyboardFocusListener);

if (incrButton != null) {
incrButton.addMouseListener(buttonListener);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -82,4 +75,4 @@ private static JFrame createAndShowGUI() {
frame.setVisible(true);
return frame;
}
}
}

0 comments on commit 312c484

Please sign in to comment.