Forums Register Login

Threading problem in java 1.5.1

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I don't think you are supposed to call requestFocus on anything but the event dispatch thread.

Can you tell us more about why you are using differen threads?

Moving to our Swing forum...
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 569 times.
Similar Threads
JInternalFrames and focus
Button enabled property not refreshing on the panel
Focusing Radio Button
Problems in using Threads in JAVA SWING program
ClassNotFoundException: org.apache.axis2.transport.SimpleAxis2Server
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:44:24.