Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JComboBox bug

2 views
Skip to first unread message

David Berrebi

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
The following program is a JApplet containing a JButton
and a JComboBox.

When you select an item of the combobox, the
combobox becomes invisible (setVisible(false))
and to make the combo visible again you have to press
the button.

The bug is:
If you select an item of the combo, the combo disappears,
which is what we want! But when we press space just immediately after
we have the following exception:

Exception occurred during event dispatching:
java.awt.IllegalComponentStateException: component must be showing on
the screen to determine its location
at java.awt.Component.getLocationOnScreen(Component.java:746)
at com.sun.java.swing.JPopupMenu.show(JPopupMenu.java:862)
at
com.sun.java.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:116)

at
com.sun.java.swing.plaf.basic.BasicComboPopup.togglePopup(BasicComboPopup.java:643)

at
com.sun.java.swing.plaf.basic.BasicComboPopup$InvocationKeyListener.keyReleased(BasicComboPopup.java:429)

at
java.awt.AWTEventMulticaster.keyReleased(AWTEventMulticaster.java:198)
at java.awt.Component.processKeyEvent(Component.java:2321)
at
com.sun.java.swing.JComponent.processKeyEvent(JComponent.java:1228)
at java.awt.Component.processEvent(Component.java:2209)
at java.awt.Container.processEvent(Container.java:904)
at java.awt.Component.dispatchEventImpl(Component.java:1809)
at java.awt.Container.dispatchEventImpl(Container.java:949)
at java.awt.Component.dispatchEvent(Component.java:1741)
at
java.awt.LightweightDispatcher.processKeyEvent(Container.java:1479)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1463)

at java.awt.Container.dispatchEventImpl(Container.java:936)
at java.awt.Component.dispatchEvent(Component.java:1741)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)

I guess this is a bug??
I do not know what to do to make that work?

Hope somebody will help me!

Here is the source:

import com.sun.java.swing.*;
import java.awt.*;
import com.symantec.itools.swing.models.StringComboBoxModel;

public class JApplet1 extends JApplet
{
public void init()
{
//{{INIT_CONTROLS
getContentPane().setLayout(null);
setSize(426,266);
comboBox.setModel(stringComboBoxModel1);
getContentPane().add(comboBox);
comboBox.setBounds(36,36,192,40);
{
String[] tempString = new String[3];
tempString[0] = "dasdaf";
tempString[1] = "adasdas";
tempString[2] = "sadasdasd";
stringComboBoxModel1.setItems(tempString);
}
//$$ stringComboBoxModel1.move(0,267);
button.setText("Show the combo");
getContentPane().add(button);
button.setBounds(132,120,84,40);
//}}

//{{REGISTER_LISTENERS
SymItem lSymItem = new SymItem();
comboBox.addItemListener(lSymItem);
SymAction lSymAction = new SymAction();
button.addActionListener(lSymAction);
//}}
}

//{{DECLARE_CONTROLS
com.sun.java.swing.JComboBox comboBox = new
com.sun.java.swing.JComboBox();
com.symantec.itools.swing.models.StringComboBoxModel
stringComboBoxModel1 = new
com.symantec.itools.swing.models.StringComboBoxModel();
com.sun.java.swing.JButton button = new com.sun.java.swing.JButton();
//}}

class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == comboBox)
comboBox_itemStateChanged(event);
}
}

void comboBox_itemStateChanged(java.awt.event.ItemEvent event)
{
try {
//Hide the JComboBox
comboBox.setVisible(false);
} catch (Exception e) {
}

}

class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == button)
button_actionPerformed(event);
}
}

void button_actionPerformed(java.awt.event.ActionEvent event)
{
try {
//Show the JComboBox
comboBox.setVisible(true);
} catch (Exception e) {
}
}

}


Dan Grieves

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
My guess is that you need to move the focus to the JButton after hiding the JComboBox:

"button.requestFocus();"

I'm not qualified to say whether it's a bug for a component to maintain keyboard focus when it's not visible.

Dan Grieves


0 new messages