gpt4 book ai didi

java - JPopupMenu 没有出现?

转载 作者:行者123 更新时间:2023-12-04 06:26:19 27 4
gpt4 key购买 nike

我有一个 Java 小程序,它将由用户必须与之交互的几个弹出菜单组成。但是,添加时 JPopupMenu 不会显示。这是我的代码:

public class Parser extends JApplet implements ActionListener {
private static final long serialVersionUID = 1L;
JPopupMenu deviceMenu;
JButton downloadButton;
Map <String, Object> deviceDict;

public void init () {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
}
catch (Exception e) {
System.err.println("createGUI didn't successfully complete");
}
}
public void createGUI() {
try {
URL url = new URL("[URL]");
URLConnection conn = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
conn.getInputStream()));
String inputLine;
String xml = "";
while ((inputLine = in.readLine()) != null)
xml = xml + inputLine;
deviceDict = Plist.fromXml(xml);
System.out.print(deviceDict);
}

catch (XmlParseException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
setLayout(new FlowLayout());
setPreferredSize(new Dimension(480, 360));
setSize(480, 360);
Iterator <String> deviceIterator = deviceDict.keySet().iterator();
deviceMenu = new JPopupMenu("Test");
while (deviceIterator.hasNext()) {
JMenuItem item = new JMenuItem(deviceIterator.next());
deviceMenu.add(item);
}
add(deviceMenu);
}
}

任何想法为什么?

最佳答案

你希望它什么时候出现?
您需要调用show()如果要显示弹出菜单。
看到这个examplethe one from oracle site .

顺便说一句 - 从你的问题看来 JDialog

关于java - JPopupMenu 没有出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004720/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com