Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ComboBoxEditor problem in WindowsLookAndFeel

Reply
Thread Tools

ComboBoxEditor problem in WindowsLookAndFeel

 
 
Ken Coe
Guest
Posts: n/a
 
      06-08-2004
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$FocusHandle r.focusGained(BasicComboBoxUI.java:466)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:162)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:161)
at java.awt.AWTEventMulticaster.focusGained(AWTEventM ulticaster.java:161)
at java.awt.Component.processFocusEvent(Component.jav a:5003)
at java.awt.Component.processEvent(Component.java:488
at java.awt.Container.processEvent(Container.java:156 9)
at java.awt.Component.dispatchEventImpl(Component.jav a:3615)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:76
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:453)
at java.awt.Component.dispatchEventImpl(Component.jav a:3506)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100)
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI$EditorActio nListener.actionPerformed(BasicComboBoxUI.java:157 4)
at javax.swing.JTextField.fireActionPerformed(JTextFi eld.java:491)
at javax.swing.JTextField.postActionEvent(JTextField. java:672)
at javax.swing.JTextField$NotifyAction.actionPerforme d(JTextField.java:786)
at javax.swing.SwingUtilities.notifyAction(SwingUtili ties.java:1530)
at javax.swing.JComponent.processKeyBinding(JComponen t.java:243
at javax.swing.JComponent.processKeyBindings(JCompone nt.java:2473)
at javax.swing.JComponent.processKeyEvent(JComponent. java:2401)
at java.awt.Component.processEvent(Component.java:490 9)
at java.awt.Container.processEvent(Container.java:156 9)
at java.awt.Component.dispatchEventImpl(Component.jav a:3615)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:627)
at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:831)
at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:741)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:592)
at java.awt.Component.dispatchEventImpl(Component.jav a:3506)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Window.dispatchEventImpl(Window.java:1606 )
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100)
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI$FocusHandle r.focusLost(BasicComboBoxUI.java:501)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:172)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:171)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMul ticaster.java:171)
at java.awt.Component.processFocusEvent(Component.jav a:5006)
at java.awt.Component.processEvent(Component.java:488
at java.awt.Container.processEvent(Container.java:156 9)
at java.awt.Component.dispatchEventImpl(Component.jav a:3615)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1713)
at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:777)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:497)
at java.awt.Component.dispatchEventImpl(Component.jav a:3506)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)
at java.awt.SentEvent.dispatch(SentEvent.java:50)
at java.awt.DefaultKeyboardFocusManager$DefaultKeyboa rdFocusManagerSentEvent.dispatch(DefaultKeyboardFo cusManager.java:145)
at java.awt.DefaultKeyboardFocusManager.sendMessage(D efaultKeyboardFocusManager.java:171)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:552)
at java.awt.Component.dispatchEventImpl(Component.jav a:3506)
at java.awt.Container.dispatchEventImpl(Container.jav a:1627)
at java.awt.Window.dispatchEventImpl(Window.java:1606 )
at java.awt.Component.dispatchEvent(Component.java:34 77)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456)
at java.awt.SequencedEvent.dispatch(SequencedEvent.ja va:93)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 454)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.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.getP rovPlanCd()));
}
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.createEmptyBord er());
// 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);
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM
WindowsLookAndFeel on non-Windows hack =?iso-8859-1?Q?Nils_O=2E_Sel=E5sdal?= Java 1 10-27-2003 04:33 PM



Advertisments