//先去除边框 setUndecorated(true); //加入标签作为关闭按钮 JLabel SubCloseLabel = new JLabel(""); //按钮的位置 SubCloseLabel.setBounds(860, 0, 40, 30); //单击监听 SubCloseLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JLabel CloseLabel=(JLabel)e.getSource(); //获取顶层窗体 SubWindow MySubWindowBuider=(SubWindow)CloseLabel.getTopLevelAncestor(); MySubWindowBuider.dispose(); } }); SubPanel.setLayout(null); //加入标签作为最小化按钮 JLabel SubMinimizeLabel = new JLabel(""); SubMinimizeLabel.setBounds(822, 0, 40, 30); SubMinimizeLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JLabel MinimizeLabel=(JLabel)e.getSource(); SubWindow MySubWindowBuider=(SubWindow)MinimizeLabel.getTopLevelAncestor(); MySubWindowBuider.setExtendedState(JFrame.ICONIFIED); } }); //拖动的标签 JLabel SubDragLabel = new JLabel(""); SubDragLabel.setBounds(0, 0, 822, 30); SubDragLabel.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { JLabel DragLabel=(JLabel)e.getSource(); SubWindow MyWindowBuider=(SubWindow)DragLabel.getTopLevelAncestor(); Point p = MyWindowBuider.getLocation(); MyWindowBuider.setLocation(p.x+(e.getX()-suborigin.x),p.y+(e.getY()-suborigin.y)); } }); SubDragLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { suborigin.x=e.getX(); suborigin.y=e.getY(); } }); SubPanel.add(SubDragLabel);