Skip to content

Commit 62706dd

Browse files
hansonrhansonr
authored andcommitted
Deferred editor for JCOmboBox
1 parent dc1c81a commit 62706dd

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JComboBox.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import javax.swing.event.PopupMenuListener;
5151
import javax.swing.plaf.ComboBoxUI;
5252

53+
import swingjs.plaf.JSComboBoxUI;
54+
5355
//
5456

5557
/**
@@ -186,6 +188,13 @@ public class JComboBox extends JComponent
186188

187189
// Flag to ensure the we don't get multiple ActionEvents on item selection.
188190
private boolean selectingItem = false;
191+
192+
/**
193+
* SwingJS tweak: Lazy creation of editor, so we need to know if the editor has
194+
* been explicitly set null using setEditor(null) or not.
195+
*
196+
*/
197+
private boolean 秘isEditorCleared;
189198

190199
/**
191200
* Creates a <code>JComboBox</code> that takes its items from an
@@ -496,7 +505,7 @@ public ListCellRenderer getRenderer() {
496505
*/
497506
public void setEditor(ComboBoxEditor anEditor) {
498507
ComboBoxEditor oldEditor = editor;
499-
508+
秘isEditorCleared = (editor == null);
500509
if ( editor != null ) {
501510
editor.removeActionListener(this);
502511
}
@@ -514,6 +523,8 @@ public void setEditor(ComboBoxEditor anEditor) {
514523
* @return the <code>ComboBoxEditor</code> that displays the selected item
515524
*/
516525
public ComboBoxEditor getEditor() {
526+
if (editor == null && !this.秘isEditorCleared)
527+
setEditor(((JSComboBoxUI) ui).createEditor());
517528
return editor;
518529
}
519530

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComboBoxUI.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ public void installUI(JComponent c) {
187187
comboBox.setRenderer(createRenderer());
188188
}
189189

190-
if (comboBox.getEditor() == null || comboBox.getEditor() instanceof UIResource) {
191-
comboBox.setEditor(createEditor());
192-
}
193-
190+
// deferred -- no reason to do this now.
191+
// if (comboBox.getEditor() == null || comboBox.getEditor() instanceof UIResource) {
192+
// comboBox.setEditor(createEditor());
193+
// }
194+
//
194195
installListeners();
195196
installComponents();
196197

@@ -225,7 +226,7 @@ public void uninstallUI(JComponent c) {
225226
comboBox.setRenderer(null);
226227
}
227228

228-
ComboBoxEditor comboBoxEditor = comboBox.getEditor();
229+
ComboBoxEditor comboBoxEditor = /** @j2sNative this.comboBox.editor && */comboBox.getEditor();
229230
if (comboBoxEditor instanceof UIResource) {
230231
if (comboBoxEditor.getEditorComponent().hasFocus()) {
231232
// Leave focus in JComboBox.
@@ -634,7 +635,7 @@ protected ListCellRenderer createRenderer() {
634635
* @return a <code>ComboBoxEditor</code> used for the combo box
635636
* @see javax.swing.JComboBox#setEditor
636637
*/
637-
protected ComboBoxEditor createEditor() {
638+
public ComboBoxEditor createEditor() {
638639
return new BasicComboBoxEditor.UIResource();
639640
}
640641

0 commit comments

Comments
 (0)