java GUI中怎样在点击JButton后,在其下边弹出一个小窗体,就像一个菜单

解决方案 »

  1.   

    根据你要实现的功能写一个小窗体miniFrame,在你的JButton中添加MouseListener,在mouseClicked(MouseEvent e)中添加代码设置miniFrame的显示位置,即根据当前鼠标坐标(e.getX(),e.getY())通过
    miniFrame.setLocation(int x,int y)设置
    public void setLocation(int x,int y)将组件移到新位置。通过此组件父级坐标空间中的 x 和 y 参数来指定新位置的左上角。