ComboBoxEditor problem in WindowsLookAndFeel

K

Ken Coe

Hi everyone, I'm posting this for a colleague: He's custom coded a
class that implements a ComboBoxEditor. He's trying to get 2
JTextFields to reside in a JPanel, and the combo box display items
from both JTextFields. This works fine in MetalLookAndFeel, but in
WindowsLookAndFeel the second JTextField is "not seen"....the cursor
doesn't go there, you can't select anything in the field, etc. Also
an error is thrown. Below you'll find the error, then the code. Any
help is appreciated:

Error:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI$FocusHandler.focusGained(BasicComboBoxUI.java:466)
at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:161)
at java.awt.Component.processFocusEvent(Component.java:5003)
at java.awt.Component.processEvent(Component.java:4888)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:768)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:453)
at java.awt.Component.dispatchEventImpl(Component.java:3506)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI$EditorActionListener.actionPerformed(BasicComboBoxUI.java:1574)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:491)
at javax.swing.JTextField.postActionEvent(JTextField.java:672)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:786)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1530)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2438)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2473)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2401)
at java.awt.Component.processEvent(Component.java:4909)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:627)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:831)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:741)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:592)
at java.awt.Component.dispatchEventImpl(Component.java:3506)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI$FocusHandler.focusLost(BasicComboBoxUI.java:501)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:172)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:171)
at java.awt.Component.processFocusEvent(Component.java:5006)
at java.awt.Component.processEvent(Component.java:4888)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:777)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:497)
at java.awt.Component.dispatchEventImpl(Component.java:3506)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.SentEvent.dispatch(SentEvent.java:50)
at java.awt.DefaultKeyboardFocusManager$DefaultKeyboardFocusManagerSentEvent.dispatch(DefaultKeyboardFocusManager.java:145)
at java.awt.DefaultKeyboardFocusManager.sendMessage(DefaultKeyboardFocusManager.java:171)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:552)
at java.awt.Component.dispatchEventImpl(Component.java:3506)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.SequencedEvent.dispatch(SequencedEvent.java:93)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
-----------------------------------------------------------------------END
ERROR

package org.bcbsal.callsession.entry;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxEditor;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ProviderComboBoxEditor implements ComboBoxEditor {

private ProviderPanel panel;
private Object oldValue;

public ProviderComboBoxEditor() {
panel = new ProviderPanel();
}

public void selectAll() {
panel.selectAll();
}

public Component getEditorComponent() {
return panel;
}

public void addActionListener(ActionListener l) {
panel.addActionListener(l);
}


public void removeActionListener(ActionListener l) {
panel.removeActionListener(l);
}

public void setItem(Object anObject) {
if (anObject == null) {
panel.setProvPlanCd("");
panel.setProvNr("");
}
else {
try {
ProviderEntryBean bean = (ProviderEntryBean) anObject;
panel.setProvPlanCd(bean.getFormattedProvPlanCd());
panel.setProvNr(bean.getFormattedProvNr());
}
catch (Exception ex) {
panel.setProvPlanCd("");
panel.setProvNr("");
}
}
}

public Object getItem() {
ProviderEntryBean newValue = new ProviderEntryBean();
try {
newValue.setProvPlanCd(Integer.parseInt(panel.getProvPlanCd()));
}
catch (NumberFormatException nfe) {
newValue.setProvPlanCd(0);
}
try {
int provNr = Integer.parseInt(panel.getProvNr());
newValue.setProvNr(String.valueOf(provNr));
}
catch (NumberFormatException nfe) {
newValue.setProvNr(panel.getProvNr());
}

return newValue;
}

private class ProviderPanel extends JPanel {
private JTextField provPlanCd;
private JTextField provNr;

public ProviderPanel() {
provPlanCd = new JTextField(3);
provPlanCd.setFont(new Font("Arial", Font.BOLD, 12));
// AbstractDocument doc = (AbstractDocument) grpNr.getDocument();
// doc.setDocumentFilter(new DigitDocumentFilter(5));
provNr = new JTextField(4);
provNr.setFont(new Font("Arial", Font.BOLD, 12));
// doc = (AbstractDocument) div.getDocument();
// doc.setDocumentFilter(new AnyCharacterDocumentFilter(3));
setLayout(new BorderLayout());
// provPlanCd.setBorder(BorderFactory.createEmptyBorder());
// provNr.setBorder(BorderFactory.createEmptyBorder());
add(provPlanCd, BorderLayout.WEST);
add(provNr, BorderLayout.EAST);
}

public void setEnabled(boolean arg) {
super.setEnabled(arg);
provPlanCd.setEnabled(arg);
provNr.setEnabled(arg);

}

public void setProvPlanCd(String provPlanCd) {
this.provPlanCd.setText(provPlanCd);
}

public String getProvPlanCd() {
return provPlanCd.getText();
}

public void setProvNr(String provNr) {
this.provNr.setText(provNr);
}

public String getProvNr() {
return provNr.getText();
}

public void selectAll() {
provPlanCd.selectAll();
provNr.selectAll();
provNr.requestFocus();
}

public void addFocusListener(FocusListener l) {
// if (grpNr != null) {
// grpNr.addFocusListener(l);
// }
if (provNr != null) {
provNr.addFocusListener(l);
}
}

public void requestFocus() {
}

public void addActionListener(ActionListener l) {
provPlanCd.addActionListener(l);
provNr.addActionListener(l);
}

public void removeActionListener(ActionListener l) {
provPlanCd.addActionListener(l);
provNr.addActionListener(l);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top