我正在使用netbeans为我正在使用的工具创建一个GUI。工具内容包含在扩展JPanel的类中,并具有一个按钮。当我点击按钮时,我想要一个弹出的窗口,其中会有其他按钮和选项,其中的内容是在另一个扩展了JPanel的类中定义的。我怎样才能做到这一点?使用另一个JPanel的JPanel创建一个弹出窗口
主类的简化代码。我删除了所有不解决这个问题的重要代码:
public class FirstPanel extends JPanel {
private JButton myButton;
public FirstPanel() {
myButton = new JButton("Button");
myButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// TO DO
}
});
}
}
然后我的第二类将看起来很相似,并负责处理所有的按钮和这样的。我怎样才能做到这一点?
@ user3280809:如果使用此路线,请改用['isPopupTrigger()'](http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html#popup)。 – trashgod