Non-Editable JTextField

    A non-editable JTextField does not display a feedback when it receives the focus. This should be the caret. I'm able to scroll the field if the content is too large.

    Any comments? How can jdk be released which such an obvious bug?

    Tested on 1.4.2_05 and 1.5 with both Windows and Metal LAFs.
      • 1. Re: Non-Editable JTextField
        I don't know if I would go so far as to call it a bug, but check out the adjustment in this thread:
        • 2. Re: Non-Editable JTextField

          This should be integrated into the LAF.
          • 3. Re: Non-Editable JTextField
            I've got a wish list, too, and think about it: Santa Claus, James Gosling, have you ever seem them together in the same room?
            • 4. Re: Non-Editable JTextField

              I know, I know! I expect Swing to be as good as Windows, OceanTheme as XP. But yesterday I discovered I can not easily switch the colours in OceanTheme like I'm used to with regular MetalTheme. But this is something for Santa, I can wait a few weeks ...

              This fixed the caret problem for all non-editable JTextField controls in the application:

              1. Define a TextFieldUI to make the caret visible:

              import javax.swing.plaf.metal.MetalTextFieldUI;
              import javax.swing.plaf.ComponentUI;
              import javax.swing.*;
              import java.awt.event.FocusAdapter;
              import java.awt.event.FocusEvent;
              import java.awt.event.FocusListener;

              public class CaretTextUI extends MetalTextFieldUI
              private FocusListener caretSetVisible ;

              public static ComponentUI createUI( JComponent c )
                        return new CaretTextUI();

                   public void installUI(JComponent c)
                        super.installUI( c );

                        caretSetVisible = new FocusAdapter()
                             public void focusGained( FocusEvent evt )
                                  JTextField f = (JTextField) evt.getComponent();

                        c.addFocusListener( caretSetVisible );

                   public void uninstallUI(JComponent c)
                        c.removeFocusListener( caretSetVisible );

                        super.uninstallUI( c );

              2. At application startup register the TextFieldUI:

              UIManager.put( "TextFieldUI", "CaretTextUI" );