1 Star 0 Fork 82

阿翔与山海经/电酱jdk8

forked from misaka00251/openjdk-1.8.0 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
add-system-property-swing.JComboBox.useLegacyMode.patch 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
diff --git a/jdk/src/share/classes/javax/swing/JComboBox.java b/jdk/src/share/classes/javax/swing/JComboBox.java
index 27a0c055a..d62330063 100644
--- a/jdk/src/share/classes/javax/swing/JComboBox.java
+++ b/jdk/src/share/classes/javax/swing/JComboBox.java
@@ -24,9 +24,12 @@
*/
package javax.swing;
+import sun.security.action.GetPropertyAction;
+
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.Transient;
+import java.security.AccessController;
import java.util.*;
import java.awt.*;
@@ -86,6 +89,16 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
*/
private static final String uiClassID = "ComboBoxUI";
+ /**
+ * Use legacy mode, rollback JDK-8072767 changes.
+ */
+ private static final boolean useLegacyMode;
+
+ static {
+ useLegacyMode = "true".equals(AccessController.doPrivileged(
+ new GetPropertyAction("swing.JComboBox.useLegacyMode", "true")));
+ }
+
/**
* This protected field is implementation specific. Do not access directly
* or override. Use the accessor methods instead.
@@ -569,7 +582,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
return;
}
- getEditor().setItem(anObject);
+ if (!useLegacyMode) {
+ getEditor().setItem(anObject);
+ }
}
// Must toggle the state of this flag since this method
@@ -1309,12 +1324,16 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
* do not call or override.
*/
public void actionPerformed(ActionEvent e) {
- setPopupVisible(false);
- getModel().setSelectedItem(getEditor().getItem());
- String oldCommand = getActionCommand();
- setActionCommand("comboBoxEdited");
- fireActionEvent();
- setActionCommand(oldCommand);
+ ComboBoxEditor editor = getEditor();
+ if ((!useLegacyMode) || ((editor != null) && (e != null) && (editor == e.getSource()
+ || editor.getEditorComponent() == e.getSource()))) {
+ setPopupVisible(false);
+ getModel().setSelectedItem(editor.getItem());
+ String oldCommand = getActionCommand();
+ setActionCommand("comboBoxEdited");
+ fireActionEvent();
+ setActionCommand(oldCommand);
+ }
}
/**
diff --git a/jdk/test/javax/swing/JComboBox/8072767/bug8072767.java b/jdk/test/javax/swing/JComboBox/8072767/bug8072767.java
index 826e4631d..3d3e42cac 100644
--- a/jdk/test/javax/swing/JComboBox/8072767/bug8072767.java
+++ b/jdk/test/javax/swing/JComboBox/8072767/bug8072767.java
@@ -41,7 +41,7 @@ import javax.swing.SwingUtilities;
* @author Alexander Scherbatiy
* @summary DefaultCellEditor for comboBox creates ActionEvent with wrong source
* object
- * @run main bug8072767
+ * @run main/othervm -Dswing.JComboBox.useLegacyMode=false bug8072767
*/
public class bug8072767 {
--
2.22.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/a-xiang-and-shanhaijing/openjdk-1.8.0_2.git
[email protected]:a-xiang-and-shanhaijing/openjdk-1.8.0_2.git
a-xiang-and-shanhaijing
openjdk-1.8.0_2
电酱jdk8
master

搜索帮助