Hi,
I have written a java program in which I have created a panel containing some text fields and buttons. In the program I am trying to set the focus on the first text field ousing the requestFocus() method.For this I am using multithreading, so that on 1 thread the components are being created and in the other thread I am invoking the focus logic. Below is my implementation for the focus setting:
public void forceFocus()
{
Runnable myRunnable = new Runnable()
{
public void run()
{
try
{
//I am making it to sleep so that other activities like enabling all
//the text fields all the buttons in the JPanel.
Thread.sleep(250);
compMandToReceiveFocus.requestFocus();
}
catch(Exception e)
{}
}
};
//As the implementation of thread sceduling is OS dependent, I am
//setting the New Thread priority to minum. This is being for all
// OS except windows.
int osType = BrowserServices.getBrowserServices().getOSID();
if((osType != BrowserServices.OS_WINDOWS_95) &&
(osType != BrowserServices.OS_WINDOWS_NT) &&
(osType != BrowserServices.OSTYPE_WINDOWS))
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
The above code was working fine on all OSes on the java 1.3.1_08. However, when I ported this program to java 1.5.1, it's giving strange results...
On jdk1.5.1 and UNIX OS, the above code is working fine. However, it's not working on Windows. When I tried to increase the sleep duration, although the cursor comes in the text filed, but the panel is frozen... I cannot enter anything on the field.
Can anybody please help me on how to solve this issue?
Thanks
I have written a java program in which I have created a panel containing some text fields and buttons. In the program I am trying to set the focus on the first text field ousing the requestFocus() method.For this I am using multithreading, so that on 1 thread the components are being created and in the other thread I am invoking the focus logic. Below is my implementation for the focus setting:
public void forceFocus()
{
Runnable myRunnable = new Runnable()
{
public void run()
{
try
{
//I am making it to sleep so that other activities like enabling all
//the text fields all the buttons in the JPanel.
Thread.sleep(250);
compMandToReceiveFocus.requestFocus();
}
catch(Exception e)
{}
}
};
//As the implementation of thread sceduling is OS dependent, I am
//setting the New Thread priority to minum. This is being for all
// OS except windows.
int osType = BrowserServices.getBrowserServices().getOSID();
if((osType != BrowserServices.OS_WINDOWS_95) &&
(osType != BrowserServices.OS_WINDOWS_NT) &&
(osType != BrowserServices.OSTYPE_WINDOWS))
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
The above code was working fine on all OSes on the java 1.3.1_08. However, when I ported this program to java 1.5.1, it's giving strange results...
On jdk1.5.1 and UNIX OS, the above code is working fine. However, it's not working on Windows. When I tried to increase the sleep duration, although the cursor comes in the text filed, but the panel is frozen... I cannot enter anything on the field.
Can anybody please help me on how to solve this issue?
Thanks