Results 1 to 4 of 4

Thread: How to Set focus to New Window in Java?

  1. #1
    Join Date
    Nov 2009
    Posts
    678

    How to Set focus to New Window in Java?

    Hi, I am trying to create my own project with the use of java application. I am getting problem while opening new form in java. I am not able to set the focus to the form which is newly opened. Can anyone help me in this case to set the focus to the newly opened form? Please reply me as soon as possible.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    re: How to Set focus to New Window in Java?

    Hi, I am also new to the java programming. I don't know how to do this. But, I have Complete Reference Java2. I think this is the best book for java programming. It is available on internet also. You can search for the moving your focus to new window in it. I think you need to read this book. Just try to read it and as I think you will be able to know what you want. Just try this. As I have started to learn java now, even though I search for it, I don't think I will able to find any solution for it. So, just try to search.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    re: How to Set focus to New Window in Java?

    Hi, I have a java code which basically call a JavaScript to open a new window and it and it will give you the focus on new window.
    Code:
    import java.applet.Applet;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.Graphics;
    import netscape.javascript.JSObject;
    
    
    public class Test extends Applet implements MouseListener 
    {
    public void start() 
    {}      
    public void stop() 
    {}
    public void init()  
    {
    addMouseListener(this);
    }
    public void update(Graphics g)  
    {
    paint(g);
    }
          
    public void paint(Graphics g)  
    {}
    public void mouseClicked(MouseEvent e) 
    {
    JSObject window = JSObject.getWindow(this);      
    Object[] args = {""};                  
    window.call("jsfunction", args);
    }
    
    public void mouseEntered(MouseEvent e) 
    {}
    public void mouseExited(MouseEvent e) 
    {}
    public void mousePressed(MouseEvent e) 
    {}
    public void mouseReleased(MouseEvent e) 
    {}
    }
    The code of java script is as follows:
    Code:
    <html>
    <head>
    <title>Test the code </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script language="javascript">
    <!--
    
    var window = null;
    
    function jsfunction(strURL)
    {
       var width = 800;
       var height = 600;
       var url = "http://www.techarena.in";
      a = (screen.availHeight - height)/2;
      b = (screen.availWidth - width)/2;
      window = window.open(url,'Window','width='+width+',height='+height+',screenX='+a+',screenY='+b+',top='+b+',left='+a);
      window.focus();
    }
    -->
    </script>
    </head>
    
    <body>
    <applet type="applet" code="TestApplet" name="TestApplet" width="100%" height="100%">
    </applet>
    </body>
    
    </html>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    re: How to Set focus to New Window in Java?

    Hi, I have use this when I was making my project for last year. It is so simple to set focus to new window in java. It just need to use the toFront() method in your code and you will get what you want. When your new form code will run, it has to be executed with this code. Means you need to use this method in your code which form you want to be in Front. So, just try to use it. I think this will help you. And also solves your problem

Similar Threads

  1. Google Chrome New Instance opens behind current focus Window
    By tHeDa! in forum Technology & Internet
    Replies: 8
    Last Post: 02-05-2012, 08:14 PM
  2. How to use Window class in java?
    By Gajananvihari in forum Software Development
    Replies: 3
    Last Post: 06-03-2010, 09:52 PM
  3. Creating a Borderless Window in Java
    By Henryosa in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 10:42 PM
  4. How to write a Focus Listener in Java?
    By The Recruiter in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 07:05 AM
  5. How to Reduce Window in Java
    By AlienKing in forum Software Development
    Replies: 4
    Last Post: 30-04-2009, 03:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,623,133.47743 seconds with 16 queries