Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6e629867
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6e629867
编写于
5月 15, 2015
作者:
A
aivanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8033069: mouse wheel scroll closes combobox popup
Reviewed-by: serb, alexsch
上级
3a1dd0e5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
295 addition
and
16 deletion
+295
-16
src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
...share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
+31
-13
src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java
...share/classes/javax/swing/plaf/basic/BasicComboPopup.java
+27
-2
src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java
...hare/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java
+3
-1
test/javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java
.../javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java
+182
-0
test/javax/swing/JComboBox/8033069/bug8033069ScrollBar.java
test/javax/swing/JComboBox/8033069/bug8033069ScrollBar.java
+52
-0
未找到文件。
src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
浏览文件 @
6e629867
...
...
@@ -125,6 +125,8 @@ public class BasicComboBoxUI extends ComboBoxUI {
protected
MouseMotionListener
popupMouseMotionListener
;
protected
KeyListener
popupKeyListener
;
private
MouseWheelListener
mouseWheelListener
;
// This is used for knowing when to cache the minimum preferred size.
// If the data in the list changes, the cached value get marked for recalc.
// Added to the current JComboBox model
...
...
@@ -375,6 +377,10 @@ public class BasicComboBoxUI extends ComboBoxUI {
comboBox
.
getModel
().
addListDataListener
(
listDataListener
);
}
}
if
((
mouseWheelListener
=
createMouseWheelListener
())
!=
null
)
{
comboBox
.
addMouseWheelListener
(
mouseWheelListener
);
}
}
/**
...
...
@@ -421,6 +427,9 @@ public class BasicComboBoxUI extends ComboBoxUI {
comboBox
.
getModel
().
removeListDataListener
(
listDataListener
);
}
}
if
(
mouseWheelListener
!=
null
)
{
comboBox
.
removeMouseWheelListener
(
mouseWheelListener
);
}
}
/**
...
...
@@ -534,6 +543,10 @@ public class BasicComboBoxUI extends ComboBoxUI {
return
handler
;
}
private
MouseWheelListener
createMouseWheelListener
()
{
return
getHandler
();
}
//
// end UI Initialization
//======================
...
...
@@ -1669,7 +1682,8 @@ public class BasicComboBoxUI extends ComboBoxUI {
//
private
class
Handler
implements
ActionListener
,
FocusListener
,
KeyListener
,
LayoutManager
,
ListDataListener
,
PropertyChangeListener
{
ListDataListener
,
PropertyChangeListener
,
MouseWheelListener
{
//
// PropertyChangeListener
//
...
...
@@ -1939,21 +1953,25 @@ public class BasicComboBoxUI extends ComboBoxUI {
public
void
actionPerformed
(
ActionEvent
evt
)
{
Object
item
=
comboBox
.
getEditor
().
getItem
();
if
(
item
!=
null
)
{
if
(!
comboBox
.
isPopupVisible
()
&&
!
item
.
equals
(
comboBox
.
getSelectedItem
()))
{
comboBox
.
setSelectedItem
(
comboBox
.
getEditor
().
getItem
());
}
ActionMap
am
=
comboBox
.
getActionMap
();
if
(
am
!=
null
)
{
Action
action
=
am
.
get
(
"enterPressed"
);
if
(
action
!=
null
)
{
action
.
actionPerformed
(
new
ActionEvent
(
comboBox
,
evt
.
getID
(),
evt
.
getActionCommand
(),
evt
.
getModifiers
()));
if
(!
comboBox
.
isPopupVisible
()
&&
!
item
.
equals
(
comboBox
.
getSelectedItem
()))
{
comboBox
.
setSelectedItem
(
comboBox
.
getEditor
().
getItem
());
}
ActionMap
am
=
comboBox
.
getActionMap
();
if
(
am
!=
null
)
{
Action
action
=
am
.
get
(
"enterPressed"
);
if
(
action
!=
null
)
{
action
.
actionPerformed
(
new
ActionEvent
(
comboBox
,
evt
.
getID
(),
evt
.
getActionCommand
(),
evt
.
getModifiers
()));
}
}
}
}
}
public
void
mouseWheelMoved
(
MouseWheelEvent
e
)
{
e
.
consume
();
}
}
}
class
DefaultKeySelectionManager
implements
JComboBox
.
KeySelectionManager
,
UIResource
{
private
String
prefix
=
""
;
...
...
src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java
浏览文件 @
6e629867
...
...
@@ -180,6 +180,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
*/
protected
ItemListener
itemListener
;
private
MouseWheelListener
scrollerMouseWheelListener
;
/**
* This protected field is implementation specific. Do not access directly
* or override.
...
...
@@ -286,6 +288,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
uninstallComboBoxModelListeners
(
comboBox
.
getModel
());
uninstallKeyboardActions
();
uninstallListListeners
();
uninstallScrollerListeners
();
// We do this, otherwise the listener the ui installs on
// the model (the combobox model in this case) will keep a
// reference to the list, causing the list (and us) to never get gced.
...
...
@@ -572,6 +575,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
scroller
.
setFocusable
(
false
);
scroller
.
getVerticalScrollBar
().
setFocusable
(
false
);
scroller
.
setBorder
(
null
);
installScrollerListeners
();
}
/**
...
...
@@ -588,6 +592,20 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
setFocusable
(
false
);
}
private
void
installScrollerListeners
()
{
scrollerMouseWheelListener
=
getHandler
();
if
(
scrollerMouseWheelListener
!=
null
)
{
scroller
.
addMouseWheelListener
(
scrollerMouseWheelListener
);
}
}
private
void
uninstallScrollerListeners
()
{
if
(
scrollerMouseWheelListener
!=
null
)
{
scroller
.
removeMouseWheelListener
(
scrollerMouseWheelListener
);
scrollerMouseWheelListener
=
null
;
}
}
/**
* This method adds the necessary listeners to the JComboBox.
*/
...
...
@@ -796,8 +814,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
private
class
Handler
implements
ItemListener
,
MouseListener
,
MouseMotionListener
,
PropertyChange
Listener
,
Serializable
{
MouseMotionListener
,
MouseWheel
Listener
,
PropertyChangeListener
,
Serializable
{
//
// MouseListener
// NOTE: this is added to both the JList and JComboBox
...
...
@@ -981,6 +999,13 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
setListSelection
(
comboBox
.
getSelectedIndex
());
}
}
//
// MouseWheelListener
//
public
void
mouseWheelMoved
(
MouseWheelEvent
e
)
{
e
.
consume
();
}
}
//
...
...
src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java
浏览文件 @
6e629867
...
...
@@ -884,7 +884,9 @@ public class BasicPopupMenuUI extends PopupMenuUI {
processMouseEvent
(
me
);
break
;
case
MouseEvent
.
MOUSE_WHEEL
:
if
(
isInPopup
(
src
))
{
if
(
isInPopup
(
src
)
||
((
src
instanceof
JComboBox
)
&&
((
JComboBox
)
src
).
isPopupVisible
()))
{
return
;
}
cancelPopupMenu
();
...
...
test/javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java
0 → 100644
浏览文件 @
6e629867
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.awt.AWTException
;
import
java.awt.Dimension
;
import
java.awt.GridLayout
;
import
java.awt.Point
;
import
java.awt.Robot
;
import
java.awt.event.InputEvent
;
import
javax.swing.JComboBox
;
import
javax.swing.JFrame
;
import
javax.swing.JPanel
;
import
javax.swing.SwingUtilities
;
import
javax.swing.UIManager
;
import
javax.swing.UIManager.LookAndFeelInfo
;
import
javax.swing.UnsupportedLookAndFeelException
;
/* @test
* @bug 8033069
* @summary Checks that JComboBox popup does not close when mouse wheel is
* rotated over combo box and over its popup. The case where popup
* has no scroll bar.
* @library ../../regtesthelpers
* @build Util
* @run main bug8033069NoScrollBar
* @author Alexey Ivanov
*/
public
class
bug8033069NoScrollBar
implements
Runnable
{
private
static
final
String
[]
NO_SCROLL_ITEMS
=
new
String
[]
{
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
};
private
final
Robot
robot
;
private
final
String
[]
items
;
private
JFrame
frame
;
private
JComboBox
cb1
;
private
JComboBox
cb2
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
iterateLookAndFeels
(
new
bug8033069NoScrollBar
(
NO_SCROLL_ITEMS
));
}
protected
static
void
iterateLookAndFeels
(
final
bug8033069NoScrollBar
test
)
throws
Exception
{
LookAndFeelInfo
[]
lafInfo
=
UIManager
.
getInstalledLookAndFeels
();
for
(
LookAndFeelInfo
info
:
lafInfo
)
{
try
{
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
System
.
out
.
println
(
"Look and Feel: "
+
info
.
getClassName
());
test
.
runTest
();
}
catch
(
UnsupportedLookAndFeelException
e
)
{
System
.
out
.
println
(
"Skipping unsupported LaF: "
+
info
);
}
}
}
public
bug8033069NoScrollBar
(
String
[]
items
)
throws
AWTException
{
this
.
items
=
items
;
robot
=
new
Robot
();
robot
.
setAutoDelay
(
200
);
}
private
void
setupUI
()
{
frame
=
new
JFrame
();
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
cb1
=
new
JComboBox
<>(
items
);
cb2
=
new
JComboBox
<>(
items
);
JPanel
panel
=
new
JPanel
(
new
GridLayout
(
1
,
2
));
panel
.
add
(
cb1
);
panel
.
add
(
cb2
);
frame
.
add
(
panel
);
frame
.
pack
();
frame
.
setVisible
(
true
);
}
public
void
runTest
()
throws
Exception
{
try
{
SwingUtilities
.
invokeAndWait
(
this
);
robot
.
waitForIdle
();
assertFalse
(
"cb1 popup is visible"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
// Move mouse pointer to the center of the fist combo box
Point
p
=
cb1
.
getLocationOnScreen
();
Dimension
d
=
cb1
.
getSize
();
robot
.
mouseMove
(
p
.
x
+
d
.
width
/
2
,
p
.
y
+
d
.
height
/
2
);
// Click it to open popup
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
robot
.
waitForIdle
();
assertTrue
(
"cb1 popup is not visible"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
robot
.
mouseWheel
(
1
);
robot
.
waitForIdle
();
assertTrue
(
"cb1 popup is not visible after mouse wheel up on combo box"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
robot
.
mouseWheel
(-
1
);
robot
.
waitForIdle
();
assertTrue
(
"cb1 popup is not visible after mouse wheel down on combo box"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
// Move mouse down on the popup
robot
.
mouseMove
(
p
.
x
+
d
.
width
/
2
,
p
.
y
+
d
.
height
*
3
);
robot
.
mouseWheel
(
1
);
robot
.
waitForIdle
();
assertTrue
(
"cb1 popup is not visible after mouse wheel up on popup"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
robot
.
mouseWheel
(-
1
);
robot
.
waitForIdle
();
assertTrue
(
"cb1 popup is not visible after mouse wheel down on popup"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
// Move mouse pointer to the center of the second combo box
p
=
cb2
.
getLocationOnScreen
();
d
=
cb2
.
getSize
();
robot
.
mouseMove
(
p
.
x
+
d
.
width
/
2
,
p
.
y
+
d
.
height
/
2
);
robot
.
mouseWheel
(
1
);
robot
.
waitForIdle
();
assertFalse
(
"cb1 popup is visible after mouse wheel up on cb2"
,
Util
.
invokeOnEDT
(
cb1:
:
isPopupVisible
));
}
finally
{
if
(
frame
!=
null
)
{
frame
.
dispose
();
}
}
System
.
out
.
println
(
"Test passed"
);
}
@Override
public
void
run
()
{
setupUI
();
}
private
static
void
assertTrue
(
String
message
,
boolean
value
)
{
assertEquals
(
message
,
true
,
value
);
}
private
static
void
assertFalse
(
String
message
,
boolean
value
)
{
assertEquals
(
message
,
false
,
value
);
}
private
static
void
assertEquals
(
String
message
,
boolean
expected
,
boolean
actual
)
{
if
(
expected
!=
actual
)
{
throw
new
RuntimeException
(
message
);
}
}
}
test/javax/swing/JComboBox/8033069/bug8033069ScrollBar.java
0 → 100644
浏览文件 @
6e629867
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.awt.AWTException
;
/* @test
* @bug 8033069
* @summary Checks that JComboBox popup does not close when mouse wheel is
* rotated over combo box and over its popup. The case where
* popup has scroll bar.
* @library ../../regtesthelpers
* @build Util
* @run main bug8033069ScrollBar
* @author Alexey Ivanov
*/
public
class
bug8033069ScrollBar
extends
bug8033069NoScrollBar
{
private
static
final
String
[]
SCROLL_ITEMS
=
new
String
[]
{
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
};
public
static
void
main
(
String
[]
args
)
throws
Exception
{
iterateLookAndFeels
(
new
bug8033069ScrollBar
(
SCROLL_ITEMS
));
}
public
bug8033069ScrollBar
(
String
[]
items
)
throws
AWTException
{
super
(
items
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录