ComboBoxEditor problem in WindowsLookAndFeel

Discussion in 'Java' started by Ken Coe, Jun 8, 2004.

  1. Ken Coe

    Ken Coe Guest

    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);
    }
    }
    }
    Ken Coe, Jun 8, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    3,952
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,139
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    1,944
    Merek
    Dec 3, 2003
  4. =?iso-8859-1?Q?Nils_O=2E_Sel=E5sdal?=

    WindowsLookAndFeel on non-Windows hack

    =?iso-8859-1?Q?Nils_O=2E_Sel=E5sdal?=, Oct 25, 2003, in forum: Java
    Replies:
    1
    Views:
    1,563
    Steve W. Jackson
    Oct 27, 2003
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    533
    Bullschmidt
    May 11, 2004
Loading...

Share This Page