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.
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.
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>
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