I am trying to synchronize popups of two combo boxes - call them comboBox and mirrorComboBox. I want to set popup of mirrorComboBox visible when popup of comboBox becomes visible.
我试图通过将PopupMenuListener添加到 comboBox身上,并在PopupVisible(true)到PopupMenuWillBecome 发生了引人注目的事件。 该公司进行罚款,但不幸的是,它又造成另一个问题—— com鱼的泛滥。 方框永远不会被隐藏。 在人口一度出现后,就从未采用流行性方法。
如何唤醒两个 com子的可见度?
Here is my implementation:
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
public class MirrorPopupsMainFrame extends JFrame implements PopupMenuListener {
public static void main(String[] args) {
new MirrorPopupsMainFrame().setVisible(true);
}
JComboBox comboBox;
JComboBox mirrorComboBox;
public MirrorPopupsMainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildUi();
}
protected void buildUi() {
String[] items = new String[]{"item1", "item2", "item3"};
comboBox = new JComboBox(items);
comboBox.addPopupMenuListener(this);
mirrorComboBox = new JComboBox(items);
setLayout(new FlowLayout());
add(comboBox);
add(mirrorComboBox);
setBounds(0, 0, 300, 200);
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
// Not calling the following line will cause
// comboBox s popup to hide correctly.
mirrorComboBox.setPopupVisible(true);
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
mirrorComboBox.setPopupVisible(false);
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {}
}