<Swing Dev> Unable to view focus in Non-Editable Text Area

Sean Chou zhouyx at linux.vnet.ibm.com
Wed Apr 13 08:54:55 UTC 2011


Hi all,

I found a similar bug was reported for JTextArea.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4512626

That bug is about JTextArea, while this is about TextArea behavior
difference.

It seems showing a caret is a general way to address this kind of
accessibility.
So I made a simple patch.

diff -r 554adcfb615e src/solaris/classes/sun/awt/X11/XTextAreaPeer.java
--- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Wed Mar 16
15:01:07 2011 -0700
+++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java	Fri Mar 18
16:31:56 2011 +0800
@@ -664,6 +664,8 @@
     class XAWTCaret extends DefaultCaret {
         public void focusGained(FocusEvent e) {
             super.focusGained(e);
+            // Make sure the cursor in visible in case of non-editable TextArea
+            super.setVisible(true);
             getComponent().repaint();
         }




2011/4/1 Sean Chou <zhouyx at linux.vnet.ibm.com>

> Hi,
>    I find that if a TextArea is set to un-editable on linux system, the
> customer will be
> unable to view the focus when the TextArea gets focused(eg. clicked). On
> windows, the cursor is blinking when the un-editable TextArea get the
> focus.
> So linux users may get confused when trying to move the focus to the
> TextArea
> because no visible feedback is given.
>
>    I think it will be better if TextArea behaves the same as it is on
> windows.
> Here is a simple testcase:
>
> import java.awt.TextArea;
> import javax.swing.JButton;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import javax.swing.JTextArea;
>
> public class NonEditable {
> public static void main(String[] str) {
> JFrame jf = new JFrame();
>  JButton jb = new JButton("click");
> JPanel jp = new JPanel();
> jf.setSize(200, 200);
>  JTextArea jt = new JTextArea(3, 3);
> jf.getContentPane().add(jp);
> jp.add(jb);
>  jp.add(jt);
> jf.setVisible(true);
> jt.setText("hello how r u");
>  jt.setEditable(false);
> TextArea ta = new TextArea(6, 10);
> ta.setText("Rajesh kumar");
>  ta.setEditable(false);
> jp.add(ta);
> }
> }
>
>
> --
> Best Regards,
> Sean Chou
>
>


-- 
Best Regards,
Sean Chou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20110413/9b6cfeb1/attachment.html>


More information about the swing-dev mailing list