🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1050

Re: JTextArea question

#1050
From: Paul Furbacher [TeamB]
Date: Thu, 22 Apr 2004 15:01
54 lines
2508 bytes
George wrote:

> I have a JTextArea in which a user types SQL Commands.  I'd like to provide
> a token-completion feature i.e when the user types CTRL-space I want to
> bring up a window with a list box of certain database object names (similar
> to what JBuilder provides in the editor).
> 
> My problem is where to position this window.  How can I go from the caret
> location of the JTextArea to the x-y coordinates needed to position the
> window?

Well, the problem should be solvable by drilling
down in the relevant component hierarchies:

Just looking at the JTextField/JTextComponent API, there's

   public Caret getCaret()


Looking at Caret, there's

   public Point getMagicCaretPosition()


If the returned point is relative to the
component itself, do the math after getting
the origin of the component.  There are
a number of relevant Component methods:

   public Point getLocation()

   public Point getLocationOnScreen()


That's how I would proceed in trying to
solve the problem.  I don't have the time
to test whether these would actually solve
your problem.  Give it a try.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://www.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <4087de4d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4086c951$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,36cb0f214b8bd976
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2004-04-22 08:04:10 PST
Date: Thu, 22 Apr 2004 11:01:45 -0400
From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com>
Organization: Reverse Alchemy, Inc.
User-Agent: Mozilla Thunderbird 0.5 (Macintosh/20040208)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: JTextArea question
References: <4086c951$1@newsgroups.borland.com>
In-Reply-To: <4086c951$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.142.222.65
Message-ID: <4087de4d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1082646093 69.142.222.65 (22 Apr 2004 08:01:33 -0700)
Lines: 54
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail