java - Set focus to other jframe -
my question related java swing frame. have 2 jframe. jframe1 , jframe2. there jbutton in jframe 1 when user click jbutton want focus frame 2(frame 2 loaded in application.) without closing frame1. please this
you can use window.tofront()
bring current frame front:
import java.awt.window; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton; import javax.swing.jframe; public class myframe extends jframe implements actionlistener { public myframe(string title) { super(title); setdefaultcloseoperation(exit_on_close); jbutton button = new jbutton("bring other myframe front"); button.addactionlistener(this); add(button); pack(); setvisible(true); } public static void main(string[] args) { new myframe("1"); new myframe("2"); } @override public void actionperformed(actionevent e) { (window window : window.getwindows()) { if (this != window) { window.tofront(); return; } } } }
Comments
Post a Comment