Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 25-11-2009
Member
 
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.
Reply With Quote
  #3  
Old 25-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
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>
Reply With Quote
  #4  
Old 25-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:28 AM.