Board index » jbuilder » Setting Focus to a control on a different frame

Setting Focus to a control on a different frame


2003-09-10 06:47:46 AM
jbuilder8
I have two frames, the first one has a jtextarea and a button. When the button is clicked another frame opens, in the textarea i have some text which I need to highlight. From frame 2 I have the following code
textArea.getParent().setFocusable(true);
textArea.getParent().requestFocus();
textArea.setFocusable(true);
textArea.requestFocus();
textArea.setCaretColor(Color.RED);
textArea.setSelectionColor(Color.GREEN);
try {
textArea.setCaretPosition(start);
textArea.moveCaretPosition(end);
}
catch (java.lang.IllegalArgumentException ex) {
//do nothing
}
System.out.println("start:" + start + " End:" + end);
in order to see the highlighted text I have to click on fram one. frame 2 is still open and it needs to stay open while I highlight the text from frame 1. Am I missing something here?
 
 

Re:Setting Focus to a control on a different frame

The highlight shows up for the focused frame only, so you have to do
frame1.requestFocus() to get the focus back there.
--
Check out our latest white papers at
www.datadevelopment.com/papers/index.html
BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server
Dolphin Data Development Ltd.
www.datadevelopment.com/
"Lans Redmond" < XXXX@XXXXX.COM >wrote in message
Quote

I have two frames, the first one has a jtextarea and a button. When the
button is clicked another frame opens, in the textarea i have some text
which I need to highlight. From frame 2 I have the following code
Quote

textArea.getParent().setFocusable(true);
textArea.getParent().requestFocus();

textArea.setFocusable(true);
textArea.requestFocus();

textArea.setCaretColor(Color.RED);
textArea.setSelectionColor(Color.GREEN);
try {
textArea.setCaretPosition(start);
textArea.moveCaretPosition(end);
}
catch (java.lang.IllegalArgumentException ex) {
//do nothing
}
System.out.println("start:" + start + " End:" + end);

in order to see the highlighted text I have to click on fram one. frame 2
is still open and it needs to stay open while I highlight the text from
frame 1. Am I missing something here?