Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

Focus question..

Thread view: 
Frances Del Rio - 05 Oct 2005 19:21 GMT
I have two text panes, one on top of window other one below (this is for
an IM window..)

I'm trying to set it up so when window opens focus is on bottom text
pane (where users type msgs)

tried several things and none of them worked:

   textAreaTop.transferFocus();
   textAreaBottom.requestFocus();
   textAreaBottom.grabFocus();

tried each one of these individually, they were all ignored..
(can't do textAreaTop.setFocusable(false) b/c need to leave that area
focusable so users can select and copy text in it; I just want it not to
be in focus when window opens (I want bottom text area to be have focus
when window opens..)

thank you very much....  Frances
Michael Dunn - 05 Oct 2005 20:55 GMT
>I have two text panes, one on top of window other one below (this is for an
>IM window..)
[quoted text clipped - 7 lines]
>    textAreaBottom.requestFocus();
>    textAreaBottom.grabFocus();

you should be using
textAreaBottom.requestFocusInWindow();

but note that the above line must be placed in your
code *after* setVisible(true);

if this doesn't work, try wrapping it in this
SwingUtilities.invokeLater(new Runnable()
{
 public void run()
 {
     textAreaBottom.requestFocusInWindow();
 }
});
Frances - 06 Oct 2005 14:51 GMT
>>I have two text panes, one on top of window other one below (this is for an
>>IM window..)
[quoted text clipped - 22 lines]
>   }
> });

hmmm...  first of all, Michael, thank you very much.. have not
forgotten, of course, all the help you gave me when I was trying to do
my little IM window..

ok, the focus thing is working now..  used the following:

               textAreaTop.transferFocus();
           textAreaBottom.grabFocus();

but you say use requestFocusInWindow() instead?  what does this do
exactly?  I did read about it in the docs, but well, don't quite get the
deal w/this method ("Every effort will be made to honor the request;
however, in some cases it may be impossible to do so.."  ;)

this focus thing is a bit more complex than it would seem at first
glance, I guess to allow for more complex applications that my present
one...;)

question I have now is re caret:  after I send message, and msg appears
in top textArea, if the msg is more than one line long, let's say two
lines, caret stays at line 2 in bottom window.. how do I make caret go
back to top line in that bottom textArea after msg has been sent?  (just
spent some time looking @ caret methods, only one that I found that
moves caret is moveCaretPosition(), but that one is used to form
selections..)

speaking of selections, I also would like to know if can set font
color/shading color for selections, for ex, if a user selects a word
make font color gray, shading dark blue for that selection..  again,
many thanks for yr help, Michael..  Frances
Frances - 06 Oct 2005 14:55 GMT
>>> I have two text panes, one on top of window other one below (this is
>>> for an IM window..)
[quoted text clipped - 53 lines]
> make font color gray, shading dark blue for that selection..  again,
> many thanks for yr help, Michael..  Frances

hmmmm....  just realized, while top area is a JTextPane, bottom one is a
JTextArea (since don't need to do diff. font colors for that one) can u
manipulate caret position on a JTextArea?  thanks again...
Andrew Thompson - 06 Oct 2005 17:12 GMT
> hmmmm....  just realized, while top area is a JTextPane, bottom one is a
> JTextArea (since don't need to do diff. font colors for that one) can u
> manipulate caret position on a JTextArea?  

Can you manipulate the caret in a text component?
(Check the Javadocs, then check which two classes,
amongst others, inheret those methods from
JTextComponent)
Roedy Green - 06 Oct 2005 20:18 GMT
>hmmmm....  just realized, while top area is a JTextPane, bottom one is a
>JTextArea (since don't need to do diff. font colors for that one) can u
>manipulate caret position on a JTextArea?  thanks again..

a JTextArea is a JTextComponent and as such inherits methods such as
setSelectionStart, setCaret, setCaretColor
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Michael Dunn - 06 Oct 2005 20:34 GMT
> but you say use requestFocusInWindow() instead?  what does this do
> exactly?

from the api docs

"The focus behavior of this method can be implemented uniformly across
platforms, and thus developers are strongly encouraged to use this method
over requestFocus when possible. Code which relies on requestFocus may
exhibit different focus behavior on different platforms."

> how do I make caret go back to top line in that bottom textArea after msg
> has been sent?

textArea.setCaretPosition(0);
Roedy Green - 06 Oct 2005 01:48 GMT
>an IM window..

IM?  
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Frances - 06 Oct 2005 14:56 GMT
>>an IM window..
>
> IM?  

sorry Roedy...  Instant Messaging...:)
Roedy Green - 06 Oct 2005 01:48 GMT
>    textAreaTop.transferFocus();
>    textAreaBottom.requestFocus();
>    textAreaBottom.grabFocus();
did you do these on the correct thread?

See http://mindprod.com/jgloss/swingthreads.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.