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 / General / June 2005

Tip: Looking for answers? Try searching our database.

caret on not editable JTextPane

Thread view: 
ndrli@yahoo.com - 23 Jun 2005 16:01 GMT
Hi,

I have a JTextPane (or JTextComponent) which works fine. When I call
setEditable(false), the caret is not visible. How can I make the caret
visible on
not editable JTextPane?

Any information would be appreciated. Thanks in advance.
Andrew Thompson - 23 Jun 2005 16:28 GMT
> Hi,
>
> I have a JTextPane (or JTextComponent) which works fine. When I call
> setEditable(false), the caret is not visible. How can I make the caret
> visible on
> not editable JTextPane?

*Why* do you (think you) need to give the end user
a caret in a non-editable text area?

Since the caret indicates the place that has the *input*
focus, and there is no input for a non editable component,
it does not make that much sense.  (And would be confusing).

Note that in this example, the text *selection* shows clearly,
that is probably all the user needs.

</sscce>
import java.awt.*;
import javax.swing.*;

public class CaretInText extends JPanel {

 CaretInText() {
   setLayout( new BorderLayout() );

   JTextPane tp = new JTextPane();
   tp.replaceSelection("Hi There!");
   tp.setCaretPosition(0);
   tp.moveCaretPosition(3);
   tp.setEditable(false);

   add( tp, BorderLayout.CENTER );
 }

 public static void main(String[] args) {
   JFrame f = new JFrame("Caret In Text");
   f.getContentPane().add( new CaretInText() );
   f.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
   f.pack();
   f.setVisible(true);
 }
}
</sscce>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

ndrli@yahoo.com - 23 Jun 2005 16:58 GMT
Why? The user can search dwon/up from the caret. If the caret is not
visible,
It is not clear from which positon to start your search.

> *Why* do you (think you) need to give the end user
> a caret in a non-editable text area?
[quoted text clipped - 42 lines]
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
Andrew Thompson - 23 Jun 2005 17:08 GMT
> Why?

Why what?  Please place comments after the text to which
you are replying, and trim any stuff to which you are
not replying.

>..The user can search dwon/up from the caret. If the caret is not
> visible,
> It is not clear from which positon to start your search.

Try offering the search from 'start of selected text'(?).

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



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.