首页 > 代码库 > 今天来个爪哇去边框的小代码
今天来个爪哇去边框的小代码
//先去除边框 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);
今天来个爪哇去边框的小代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。