English 中文(简体)
• 如何协调两个JComboBoxes(comboBox和Box)的流行
原标题:How to synchronize popups visibility of two JComboBoxes (comboBox and mirrorComboBox)

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) {}

}
问题回答

暂无回答




相关问题
auto abbreviating JLabel

Anyone written a JLabel (extension/util/??) that automatically abbreviates the contents depending on it s preferred/visible size? much appreciated.

how can install swing/matisse on eclipse?

i tried this link: http://downloads.myeclipseide.com/downloads/products/eworkbench/discovery-6.0/ but i m fail how is this?

Java JTextField with input hint

I would like to add a hint value to my javax.swing.JTextField. It should look like Firefox rendering of <input type="text" title="bla">. This creates an edit field with the text bla in the ...

Swing Generator

I need to develop some java gui using swing. A few years ago I did develop a bit with swing. But it was pretty exhausting, you see, back than there weren t much tools to help you. But I do believe ...

Create a ImageIcon that is the mirror of another one

I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...

热门标签