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

Sean Chou zhouyx at linux.vnet.ibm.com
Fri Dec 9 01:06:43 PST 2011


Hi all,

    I reported a bug about "Unable to view the focus in Non-Editable Text
Area",
whose link is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7119745 .

    The detail is when TextArea is set to un-editable on linux system, the
customer will be unable to view the focus when the TextArea gets focused.
So linux users may get confused when trying to move the focus to the
TextArea
because no visible feedback is given.

    There is a related bug about swing components:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4512626
In its description, it says caret should be shown. So I prepared a simple
fix at http://cr.openjdk.java.net/~zhouyx/7119745/  .

Here is a test case, run with java7 on linux platform, and move the
focus to TextArea. The caret is not shown as expected.

 Please have a look.


/////////////////////////////////////////////
import java.awt.TextArea;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class OJDK103 {

    public static void main(String[] str) {
        JFrame jf = new JFrame();
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        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);
    }

}




On Fri, Dec 2, 2011 at 5:18 PM, Neil Richards <neil.richards at ngmr.net>wrote:

> On Wed, 2011-04-13 at 16:54 +0800, Sean Chou wrote:
> > 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
> >
>
> Hi Sean,
> As your observation is about an AWT object (rather than a Swing one), I
> think it best to raise this on the 'awt-dev' list.
>
> I've cc'd this list so the folk there can consider your suggestion.
>
> Regards, Neil
>
> --
> Neil Richards <neil.richards at ngmr.net>
> IBM
>
>


-- 
Best Regards,
Sean Chou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/awt-dev/attachments/20111209/d28c94cc/attachment.html 


More information about the awt-dev mailing list