I am now in an awkward situation and so I am here to get some expert advice. I have an Editable JComboBox
. I have implement actionPerformed
event which just works fine. But I have implement mouseListener
which is not working.
component = jcbItemType.getEditor().getEditorComponent();
component.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseClicked(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
jcbItemTypeMousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
});
I have also tried the following code:
Component[] comps = jcbItemType.getComponents();
for(int i = 0; i < comps.length; i++)
{
comps[i].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseClicked(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
jcbItemTypeMousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
jcbItemTypeMouseReleased(evt);
}
});
}
I know that JComboBox
is a compound element and hence direct mouse handling event will not work. But I have use the individual component's mouseListener
but it is not working too.
Someone can ask about stateChanged
event but I want to load some information after an item is fully selected and NOT when I just type 2/3 characters of an item. In stateChanged
event, it's got heavily loaded if it shows the item information only after 2/3 characters since my information against each item is heavy weighted.
So, how can I get the event when an item is selected by mouse click?
The following link solve my problem.
http://engin-tekin.blogspot.com/2009/10/hrefhttpkfd.html
The code snippet from the link is below: