Java – jcombobox on JPopupMenu
•
Java
I'm trying to use composite swing components as part of the menu
Everything works well except for one detail: the component contains JCombo@R_587_2419 @Es, whenever the user clicks one of them to open its drop-down list, the drop-down list opens but the menu disappears single click JCombo@R_587_2419 @Is it possible to keep the menu open when?
I classified JMenu This is the corresponding code:
public class FilterMenu extends JMenu { public FilterMenu(String name) { super(name); final jpopupmenu pm = this.getPopupMenu(); final FilterPanel filterPanel = new FilterPanel(pm) { @Override public void updateTree() { super.updateTree(); pm.pack(); } }; pm.add(filterPanel); } }
Filterpanel is a custom composite component Call PM Pack() to resize the JPopupMenu when the filterpanel size changes
Thanks for your help
Solution
You mean this bug
import javax.swing.*; import java.awt.event.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(400,400); frame.setVisible(true); String[] list = {"1","2","3","4",}; JCombo@R_587_2419@ comb = new JCombo@R_587_2419@(list); final jpopupmenu pop = new jpopupmenu(); pop.add(comb); frame.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { System.out.println("mousePressed"); pop.show(e.getComponent(),e.getX(),e.getY()); } }); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码