Moving the caret in a non-editable JTextPane ??

Hi,
I would like to know if it's possible to have a visible and moveable caret (with the directional arrows) in a JTextPane which has to be non editable.
If you know how to do, could you please answer and give the solution
Thanks in advance

Every text component has its own caret. It would look ugly to have the caret flashing for every text component on the screen, so when a text component loses focus the the caret is hidden - setVisible(false).
When an editable text component regains focus the caret is set visible automatically. For uneditable text components you have to set the caret visible yourself.
textPane.addFocusListener( new FocusAdapter()
     public void focusGained(FocusEvent e)
          JTextComponent component = (JTextComponent)e.getSource();
          component.getCaret().setVisible(true);
});

Similar Messages

  • Character position in non-editable JTextPane

    OK, I was hoping someone could point me in the right direction.
    I have a non-editable JTextPane ( actually a separate class that extends JTextPane ) with a mouse listener on it. I wish to be able to click on it and get a character position.
    Setting/getting a caret position would make this a no-brainer, but an caret position is an onsertion point, no? And since the JTextPane is non-editable, I would not expect to be able to set/get the caret position with a mouse click.
    Also, I suppose it would be relatively easy to get a character position from the x,y co-ordinate if I used a mono-spaced font, but I would rather not use a monospaced font if i can help it.
    So I am at a loss as to how to proceed with this. Any help here would be much appreciated.

    When a text component such as JTextPane is not editable, it still has the notion of a caret position, it's just that the caret is not visible, and modification of the text is forbidden. That's why you can use the arrow keys or page up/down to scroll through a non-editable text component.
    For any JTextComponent, to find the offset into the document the user clicks on, simply use textComponent.viewToModel() in your MouseListener implementation.
    If you have further trouble, post an SSCCE demonstrating your problem.

  • How to make the message choice as non-editable thru personalization

    Hi,
    I have one requirement to make the messageChoice field as non-editable, how to do this thru personalization for particular page.
    because the same region available in some other pages also, so i need to do only for that page.
    How to do?
    Thanks in advance,
    SAN

    Hi Shanthi,
    If you want to make some rows editable and some as read-only, then the best thing to do is use an iterator. It is basically a class that implements interface IF_HTMLB_TABLEVIEW_ITERATOR and allows you to change properties of each cell of your table. You can do the following:
    1. Create an iterator class that implements this interface.
    2. Code method RENDER_CELL_START( ) to set all elements of a given row as read-only or editable as required.
    3. Leave other two methods empty but do activate them.
    4. Declare a public reference in your view implementation class of same type as this iterator class.
    5. Pass this iterator class to 'iterator' attribute of your <chtmlb:configTable> in view htm.
    In the iterator class, you also need to access your table node to decide which rows to make editable and which row to make readonly. To do this, you can declare an attribute in this class of type CL_BSP_WD_CONTEXT_NODE_TV and instantiate it from the CONSTRUCTOR. And you can instantiate this iterator class from DO_VIEW_INIT_ON_ACTIVATION( ) of your view controller.
    Regards,
    Shiromani

  • How to insert a String at the CaretPosition without moving the Caret?

    I have a JTextPane wrapped by a JScrollPane. The JTextPane is where chatroom messages appear. When a message is appended at the end, it determines whether to scroll to the bottom based on some conditions (scroll to the bottom only if the user was already viewing somewhere near the bottom). That part is working fine.
    Although the JTextPane is not editable, it allows the user to make selections using a mouse so that blocks of text can be copied from the chatroom. The default caret of JTextPane handles that for me.
    But the problem comes when the caret position is at the end of the document when my program inserts a new message with the following code:
    StyledDocument doc = textPane.getStyledDocument();
    doc.insertString(doc.getLength(), message + "\n", null);The caret was at doc.getLength() to begin with, when the new message is inserted at the end, it "pushes" the caret to a new position. The caret movement is causing JScrollPane to scroll to where the caret is visible (the bottom), therefore interfering with my scrolling algorithm (see above).
    So, when the caret is doc.getLength(), how do I insert a String at doc.getLength() with the caret staying at the original position?
    In other words, how do I insert a String at the caret position without the caret being moved?
    Note:
    1) I don't want to use setCaretPosition() to set the caret to its original position, because calling this method will trigger a CaretEvent, thus causing the JScrollPane to scroll (to the caret) which is not what I want (see above).
    2) I don't want to remove the CaretListener, cause then the JScrollPane won't scroll even when the user wants to make a multiple-page selection using the mouse (dragging the selection off screen).
    3) I want to keep the Caret at the original position so that the user won't lose his/her selection when new messages appear (which can be quite frequent).

    I keep forgetting how difficult it is to do such simple things in the text package. But it's not impossible! Here's a way to replace the relevant listeners, plus a sample implementation. If you know you'll never, ever delete any text from the JTextPane, you may not have to provide a replacement DocumentListener at all; this one just makes sure the caret isn't past the end of the document.
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.text.DefaultCaret;
    import javax.swing.text.Document;
    import javax.swing.text.JTextComponent;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    public class ChatCaret extends DefaultCaret
      private MyHandler newHandler;
      private PropertyChangeListener oldHandler;
      public void install(JTextComponent c)
        super.install(c);
        PropertyChangeListener[] pcls = c.getPropertyChangeListeners();
        for (int i = 0; i < pcls.length; i++)
          if (pcls.getClass().getName().equals(
    "javax.swing.text.DefaultCaret$Handler"))
    oldHandler = pcls[i];
    newHandler = new MyHandler(oldHandler);
    c.removePropertyChangeListener(oldHandler);
    c.addPropertyChangeListener(newHandler);
    break;
    Document doc = c.getDocument();
    if (doc != null)
    doc.removeDocumentListener((DocumentListener)oldHandler);
    doc.addDocumentListener(newHandler);
    public void deinstall(JTextComponent c)
    super.deinstall(c);
    c.removePropertyChangeListener(newHandler);
    Document doc = c.getDocument();
    if (doc != null)
    doc.removeDocumentListener(newHandler);
    class MyHandler implements PropertyChangeListener, DocumentListener
    private PropertyChangeListener oldHandler;
    MyHandler(PropertyChangeListener oldHandler)
    this.oldHandler = oldHandler;
    public void propertyChange(PropertyChangeEvent evt)
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    if ((oldValue instanceof Document) ||
    (newValue instanceof Document))
    setDot(0);
    if (oldValue != null)
    ((Document)oldValue).removeDocumentListener(this);
    if (newValue != null)
    ((Document)newValue).addDocumentListener(this);
    else
    oldHandler.propertyChange(evt);
    public void removeUpdate(DocumentEvent evt)
    int length = getComponent().getDocument().getLength();
    if (length < getDot())
    setDot(length);
    public void insertUpdate(DocumentEvent evt) { }
    public void changedUpdate(DocumentEvent evt) { }

  • Changing the font of a non-editable ComboBox

    Hello everyone,
    I need a small combobox. So I set a font of a specific size to the combo's
    editor. That works nice als long as the combo is editable; but when it becomes
    uneditable, the default bold font is used and some items don't fit in the
    field any more. How to prevent this?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    class ComboEditorFont extends JFrame {
      Font fontM= new Font("Monospaced", Font.PLAIN, 13);
      public ComboEditorFont() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(100,100);
        setLayout(null);
    //  Changing the font in the UIManager doesn't work either
    /*    Font defaultComboBoxFont= UIManager.getFont("ComboBox.font");
        FontUIResource fui= new FontUIResource(fontM);
        UIManager.put("ComboBox.font", fontM);
    //    UIManager.put("ComboBox.font", fui);
        JComboBox cmb = new JComboBox(new String[]{"ABC","DEF","GHI","LMO"});
        cmb.setBounds(20,20, 48,20);
    //    cmb.setEditable(true);
        JTextField editor= (JTextField)(cmb.getEditor().getEditorComponent());
        editor.setFont(fontM);
    //    cmb.setRenderer(new MyCellRenderer());
        add(cmb);
    //    UIManager.put("ComboBox.font", defaultComboBoxFont);
        setVisible(true);
      public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
         new ComboEditorFont();
      class MyCellRenderer extends JLabel implements ListCellRenderer {
        public MyCellRenderer() {
          setOpaque(true);
        public Component getListCellRendererComponent(JList list,
                                                       Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus) {
          setFont(fontM);
          setText(value.toString());
          Color background;
          Color foreground;
          JList.DropLocation dropLocation = list.getDropLocation();
          if (dropLocation!=null && !dropLocation.isInsert() &&
           dropLocation.getIndex() == index) {
         background = Color.BLUE;
         foreground = Color.WHITE;
          } else if (isSelected) {
         background = list.getSelectionBackground();
         foreground = list.getSelectionForeground();
          } else {
         background = list.getBackground();
         foreground = list.getForeground();
          setBackground(background);
          setForeground(foreground);
          return this;
    }

    - an offense to the english grammarThe exaggeration was meant to be ironic, not mean. Seriously, if a post is unreadable why bother posting it at all?
    offense/non offense, I'd start to teach this language on 15/oct/2009, untill now ---> MSDN, ASM,I don't know if you refer to the Java or English language...
    Either way, hopefully you have merely started learning it - not teaching it! :o)
    - ranging from slightly to completely off-topic
    always exists the different way, my off-topic "for you hide" declaracion for topic,
    I agreed with some rules, disagre with strict..., Swing = something based on variable interpretations about Java decl., isn't exist stricts borders there, only God can tell us, If is it Swing, or if isn't Swing relevants, not my trully,No, no, I meant "off-topic" with regard to the poster's question: he had tackled the problem for editable comboboxes already, and was specifically talking about non-editable comboboxes, so obviously altering the editor as you suggested was hopeless.
    - giving out "coding advice" without any justification
    be sure that 99pct from "answers" fired these guys find out the "coding advice" on Go..., on another forum(s), and they will not returns back here anymore, for not-acceptable Hot Potato Games (if is or isn't topic relevant for this forum), I'm afraid the grammar prevented me to understand this whole sentence...
    help is by Camickr's company, by German Kommunität (rel. for EU TimeZone), I'm only to learn (somehow) this language, Read - Translate ---> T - Write, An online translation system may help you to read these forums, but really don't post text translated this way!
    with peaceFullFace and takeAnyNoticeOfIt kopik,No personal offense meant, I now think you're well-intended (but really awkward all the same).
    Edited by: jduprez on Nov 6, 2009 4:06 PM - fixed spelling - mind you, I'm not a native english speaker either!

  • Making the whole po line item as a non editable one (Greyed out)

    Hi all
    can any one please let me know is there is any way we can grey out the whole line item,
    i mean to say non editable mode.
    i am working on a user exit where based on certain field entries i have to make the whole line
    item as an non editable one.
    For example po change transaction if there are 5 line items i want to make the three as a non editable one and i have a user exit
    with me but dont have the idea of how to make it geryed out.
    Thanks in advance.
    Joe

    Hi
    Do you have a PO release strategy implemented. This can be done through PO release strategy. please tell  the exact requirement whether this is for all users ???
    hope it will help
    Regards

  • Changing JList non-editable Font color of the selected items

    Hi All,
    I want to change the font color of non-editable JList's selected items which is not clearly visible to user. And I need to change the font color only the selected item in this scenerio.
    Could you please clarify me?
    <img src="file:///C:/DOCUME~1/sgnanasi/LOCALS~1/Temp/moz-screenshot-4.png" alt="" />

    [email protected] wrote:
    ..I want to change the font color of non-editable JList's selected items which is not clearly visible to user. And I need to change the font color only the selected item in this scenerio.Set a custom [cell renderer|http://java.sun.com/javase/6/docs/api/javax/swing/ListCellRenderer.html] *(<- link)* for the JList.

  • How to make non editable field after requestor created the shoping cart

    Hi,
    i need to make non editable field (Price field) after requester created the shooping cart.The field should be  non editable only for requster .
    this i need to make when workflow triggers when the buyer sends  back the shopping cart to requester.
    one solution which i found:depend on the status of the shoping cart
    but i dont know whether it is correct way.
    if not please suggest me the solution.

    Hi,
    You can implement the BADI" BBP_UI_CONTROL_BADI".
    You can check for the role of the user who has logged in(e.g. for user REQUESTER,there will be a distinct role to idnetify that the user is a requester) and then acc set the display properties for the field PRICE.
    For sample code pls refer the foll links:
    Sample code for BBP_UI_CONTROL_BADI
    Re: Hiding Shopping Cart Fields in SRM 3.0
    Re: How to Hide the attributes from template BBPSC01?
    Re: How to validating total value in shopping cart
    Re: Price filed in Shopping cart should be in display mode
    BR,
    Disha.

  • Disable vertical movement of the caret in a JTextArea

    Hello all,
    I have a JTextArea where the user should be able to edit only the last (current) line. Whenever the user presses CURSOR_UP, the caret shouldn't move. Moving the caret to the left and right should be possible.
    Could anyone give me a hint, where to realise that?
    Thanks in advance!
    Juergen

    Try changing the input map for your text area.
    Refer to the java doc on the following:
    JComponent.getInputMap();
    JComponent.getActionMap();
    I think, in your case nulling the Down arrow and Up arrow key in the input map would solve your problem.
    Hope this helps
    Sai Pullabhotla

  • Textfields in advanced search from LOV non-editable

    I have a LOV where the textfields in advanced search are always non-editable. When I look into the LOV JSP page, maxlength of the textfields is 0.
    One of the textfields uses following attribute:
    in EntityObject: attribute "Kuerzel", type "String" (database datatype VARCHAR2(10))
    in ViewObject: attribute "DspKuerzel"
    in the JHeadstart ADF BC Property Editor from EntityObject and ViewObject the Setting "maximum length" of the attribute is not set (no entry). Jheadstart help says that when maximum length is set to 0 then the corresponding textfield is non-editable. But here it is not set. Is there a solution to this problem?

    If you send a testcase to [email protected] and rename extension .zip to .zipped we can investigate why the maximum length is not generated correctly in your situation.
    Steven Davelaar,
    JHeadstart Team.

  • Save PDF form into non editable PDF through button (SaveAs) using java script

    I am creating PDF form using LiveCycle 8.0.
    1) Using SaveAs the form in PDF (non editable) by using button and javascript
      ( app.execMenuItem("SaveAs");
         myScript.LoclAllFields("form1");) this code is not working.
    2) show / hide the field by choosing the drop down List.
    Like, In drop down list their is tree option name  a, b, c. when select "A" hide the field_A and select "B". then show the field_A.

    Thanks for that script, it is a great way of securing it from being edited, but reader still won't allow the form to be saved, only as a copy without the inputted text. The idea of what I'm trying to achieve is a form which the staff here fill out and then send to our customers with non editable fields, there is the option to print to pdf but that saves the file as an 'image', this stops people from highlighting text which we don't want, they have to be accessible afterwards to copy and paste the text at a later date.
    I hope someone can help with what should be such a simple action.

  • FIELD BSEG - ZUONR NON EDITABLE IN FB02

    Hi guys,
    I went to "Document Change Rules, Line Item" in SPRO inserting BSEG-ZUONR as Field Name and put a tick on "Field can be Changed".
    Unfortunatly nothing happened in FB02 and the field is still non-editable.
    Could you suggest me a solution?
    Thanks a lot

    HI,
    As mentioned in note 827413 there is a golden rule regarding the changeability of fields in FI documents:
    When the field is used in Special Ledger field movement then it    is not possible to change this field in FI using transaction FB02.
    The reason is that Special Ledger is only updated when the document is created. For other components like profit center accounting or special ledger a subsequent change in an FI document is only local. Special Ledger does not get the information about the change. Thus, in order to avoid inconsistencies between SL and FI those fields are not changeable.
    Please check the follwong field movements for Special Ledger which contain the field ZUONR in the field movement (tr. GCL3).
    Regards
    Ravinagh Boni

  • Non-editable view after succesful save of complaint

    Hello,
    We want to make the view of Complaints non-editable after succesful save of the Complaint.
    I think I must add some code in method EH_ONSAVE of component BT120H_CPL/ OVViewset.
    Do you have any idea of how to achieve this?
    Best Regards.

    Thanx for you answers.
    I understand that with your solutions the entire transaction will be locked for every user.
    But what I need is to lock the business transaction in one status for certain users.
    For example...
    The IC_AGENT is creating a Service Request when he save the document another process take the document to determine some values.
    The standard behavior is... After saving the document, the document stay open in the IC_AGENT screen and what I need is to change it to view mode so the backgroung process can take the document and determine the values.
    Any idea?
    Best Regards.

  • ME22N - Make MEPO1211-EEIND non editable

    Hello Experts!
    I have the requirement to make non editable the field EEIND in ME22N.
    The Screen is 1211 in program SALMEGUI,
    I've seen others thread but didnt work for me ( becouse other thread was about addin fields )
    Any idea of an Enhacement or Exit to this problem?
    Thanks!

    Hello friends,
    I'm trying to make the field Collective number ( ekko-submi ) non editable only for a specific document type, using the logic above.
    I change the badi ME_PROCESS_PO_CUST method FIELDSELECTION_HEADER with the code below. My problem is this method is not called in program LMEPOBADIU07 (FM MEPOBADI_FS_HEADER), becouse the insert command fails in the following code. Anybody already know this problem?
       LOOP AT ch_fieldselection ASSIGNING <fs1> WHERE metafield GE mmmfd_cust_01.
         INSERT <fs1> INTO TABLE lt_fieldselection.
       ENDLOOP.
       IF sy-subrc IS INITIAL.
         CALL METHOD l_instance_cust->fieldselection_header
    The values in mmfd_cust_01 is '  90000000' (with 2 spaces in left side) and ch_fieldselection is
    METAFIELD     FIELDSTATUS
             9 |.                                                            
            11 |+                                                            
            12 |.                                                            
            13 |+                                                            
            14 |.                                                            
            27 |.                                                            
            29 |.                                                            
           303 |.                                                            
           304 |.                                                            
           305 |.                                                            
           306 |.                                                           
           307 |.                                                            
    Code writen in BADI:
    METHOD if_ex_me_process_po_cust~fieldselection_header .
      DATA: l_persistent TYPE mmpur_bool,
            l_changeable TYPE mmpur_bool,
            mmmfd_coll_no TYPE mmpur_metafield VALUE 016,
            mmmfd_doc_typ TYPE mmpur_metafield VALUE 201,
            l_header TYPE mepoheader.
      FIELD-SYMBOLS: <fs> LIKE LINE OF ch_fieldselection.
    * if the item is already on the database,
    * we disallow to change field badi_bsgru
      l_persistent = im_header->is_persistent( ).
      l_changeable = im_header->is_changeable( ).
      l_header = im_header->get_data( ).
      IF l_changeable IS NOT INITIAL AND l_header-bsart EQ 'FI'.  "(me22n) AND OTHER CONDITIONS
        READ TABLE ch_fieldselection ASSIGNING <fs>
            WITH TABLE KEY metafield =  mmmfd_coll_no.
        <fs>-fieldstatus = '*'. " view
      ENDIF.
    ENDMETHOD.

  • How to get JTextPane partially non-editable?

    Hi,
    I am trying to get parts of the JTextPane (that have clearly different styles than regular text) to be non-editable. So far I cannot make a partial setting like this. Netbeans (FFJ) source file editor has a feature like this, but I have not been able to locate their implementation in the source files. Once can move the caret inside the non-editable part, and even select text, but no editing is allowed.
    Does anybody know how to set this up?

    Here's the answer I found in 10 minutes, after having the time to take a look into it:
    The non-editable text (section headers) are blue and bold. So here's the event handler for KeyEvent:
    private void textAreaCommandKeyTyped(java.awt.event.KeyEvent evt) {
    AttributeSet aSet = textAreaCommand.getCharacterAttributes() ;
    boolean bold = StyleConstants.isBold( aSet ) ;
    if ( bold ) {
    Toolkit.getDefaultToolkit().beep();
    evt.consume() ;
    }

Maybe you are looking for

  • ITunes 7.1 in Vista - Extremely poor video playback

    Has anyone had problems watching movies on the 7.1 version of iTunes with Vista. I am using Home Premium Edition on a Core2Duo with 2 GBs of RAM and a GeForce 7900 PCie. The system is about 3 weeks brand new. This is the first install of iTunes on th

  • Tips/tricks/mod with KT6V bios???

    Hey guy's, iv got a problem with my KT6V not overclocking well, wont go over 180fsb with my 2600+ barton is there any bios mods/tricks i should know about? i cant lock my PCI/AGP............only memory witch is kingsten 3200/400mhz MSI KT6V (7021) ve

  • HR : FI to HR mapping

    Any could please provide me any Function modules or solutions to map FI cost cents to HR Organizational units. or any other way to map FI costcenters to HR data, so that we can find a relation to map.

  • Account Owner added to Opportunity Team when creating a new Opportunity

    We´ve noticed that the Account Owner is added automatically to the Opportunity Team when we create a new Opportunity. Is it possible to disable this behaviour ? txs. for your help. Antonio

  • Photoshop CS5 crashes when request print or hit print settings button!

    Photoshop CS5 crashes after I upgraded to Maverick when I ask it to print or click on Print Settings?