First remove the Border setundecorated (true);//Add the label as the Close button JLabel Subcloselabel = new JLabel ("");//The position of the button subcloselabel.setbounds (860, 0 , 40, 30);//Click Listen Subcloselabel.addmouselistener (New Mouseadapter () {@Overridepublic void mouseclicked (MouseEvent e) { JLabel closelabel= (JLabel) E.getsource ();//Get top-Level form Subwindow mysubwindowbuider= (subwindow) Closelabel.gettoplevelancestor (); Mysubwindowbuider.dispose ();}}); Subpanel.setlayout (null);//Add label as minimized button JLabel Subminimizelabel = new JLabel (""); Subminimizelabel.setbounds (822, 0, 40, 30); Subminimizelabel.addmouselistener (New Mouseadapter () {@Overridepublic void mouseclicked (MouseEvent e) {JLabel Minimizelabel= (JLabel) E.getsource (); Subwindow mysubwindowbuider= (Subwindow) minimizelabel.gettoplevelancestor (); Mysubwindowbuider.setextendedstate (jframe.iconified);}}); /Drag the label JLabel Subdraglabel = new JLabel (""); Subdraglabel.setbounds (0, 0, 822, 30); Subdraglabel.addmousemotionlistener (New Mousemotionadapter () {@Overridepublic 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 () {@Overridepublic void mousepressed (MouseEvent e) {suborigin.x= E.getx (); Suborigin.y=e.gety ();}); Subpanel.add (Subdraglabel);
A little code for a Javanese border today.