Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4309079

When a JInternalFrame is activated, focused JTextField doesn't show cursor.



    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.3.1
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
    • CPU:
      generic, x86
    • OS:
      generic, windows_98, windows_nt



        Name: skT88420 Date: 02/01/2000

        java version "1.3.0rc1"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
        Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

        When a JInternalFrame is activated, couple of problems are seen:

        1) The first JTextField on the frame does not have focus as it should when the
        frame is opened for the first time. Bug #4109910 indicates that this was
        corrected and should work in JDK 1.3, but it doesn't.

        2) After a JTextField obtains focus and its parent frame is deactivated and
        then reactivated, the caret cursor no longer blinks in the field even though
        the field does have focus (typing will put text in field).

        You can replicate the problem by using the sample code below:

        public class CursorTest extends JFrame {

        JDesktopPane desktop = new JDesktopPane();

        public static void main(String[] args) {
        new CursorTest();

        public CursorTest() {
        setSize(500, 300);


        private void AddFrame() {
        JInternalFrame frame = new JInternalFrame();
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(new JTextField(10));
        frame.getContentPane().add(new JTextField(5));
        frame.setSize(300, 200);

        (Review ID: 100646)

        Name: skT88420 Date: 02/11/2000

        java version "1.3.0rc1"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
        Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

        Can't give JTextField the focus by clicking on it after minimizing and then
        restoring a JInternalFrame which contains it.

        1. Modifiy InternalFrameDemo.java from the SwingSet2 demo app that comes with
        JDK1.3RC to include the following line in the ImageScroller() method:

                              p.add(new JLabel(icon), BorderLayout.CENTER);
         /*add this line-->*/ p.add(new JTextField(), BorderLayout.NORTH);

        2. Run this modified version of InternalFrameDemo as an app.
        3. Select the JTextField in the top of Frame4. The cusor will blink in the
        JTextField showing it has focus.
        4. Minimize Frame4
        5. Double click on the minimized Frame4 to restore it
        6. Try to click in the JTextField. You can not give it focus, the flashing
        cursor will not appear.
        This only seems to happen if there is more than one JInternalFrame in the
        JDesktop at a time.
        It also does not happen with Frame0 in the demo because Frame0 is in a
        different layer. I changed it's layer to be the same as the rest of the
        JInternalFrames and then it exhibited the same behavior.

        This did not happen in JDK1.2.x or 1.3BETA.
        (Review ID: 101142)

        Name: ks88420 Date: 09/05/2000

        java version "1.3.0rc1"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
        Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

        I have an application that uses JDesktopPane for implementing MDI application.
        I create two JInternalFrames and put inside it a JScrollPane which contains
        JEditorPane. When I press on the title bar of the first internal frame and then
        write something, then press on the title bar of the second internal frame, then
        go back to the first internal frame - the caret is gone and I can't see the
        selection (if I try to select the text I entered). I can still write on the
        editor pane but I can't see the caret. If I hide the entire frame (put another
        window on it or iconify it) the caret is displayed again (until I press the
        second internal frame). If I have a text field on the main JFrame but outside
        of the JDesktopPane and move the focus to it, and then back to the internal
        frame the caret is displayed again.

        2.Source Code (contains the text field and the creation of JDesktopPane and two
         * Test.java
         * Created on August 27, 2000, 10:56 AM
        import javax.swing.*;
        import javax.swing.event.*;
        import java.awt.event.*;
        import java.awt.*;

         * @author ONivy
         * @version
        public class Test2 extends JFrame implements CaretListener{
            private JMenu _menu;
            private ButtonGroup _buttonGroup;

            /** Creates new Test2 */
            public Test2() {

                JDesktopPane desktop = new JDesktopPane();
                JPanel p = new JPanel ();
                p.add (new JTextField ("ALon"));
                JEditorPane editor1 = new JEditorPane();
                //editor1.addFocusListener(new MyFocusAdaptor());
                JInternalFrame jif1 = new JInternalFrame("one");
                //jif1.addFocusListener(new MyFocusAdaptor());
                jif1.getContentPane().add(new JScrollPane(editor1));
                jif1.addInternalFrameListener(new WindowListener(editor1));
                JEditorPane editor2 = new JEditorPane();
                //editor2.addFocusListener(new MyFocusAdaptor());
                JInternalFrame jif2 = new JInternalFrame("two");
                //jif2.addFocusListener(new MyFocusAdaptor());
                jif2.getContentPane().add(new JScrollPane(editor2));
                jif2.addInternalFrameListener(new WindowListener(editor2));
                addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
            public static void main (String args[]) {
                new Test2().show();
            /** Called when the caret position is updated.
             * @param e the caret event
            public void caretUpdate(CaretEvent e) {
                if (e.getDot() != e.getMark()) {
            class WindowListener extends InternalFrameAdapter{
                private JEditorPane _editor;
                public WindowListener(JEditorPane editor){
                    _editor = editor;
                public void internalFrameActivated(InternalFrameEvent e){
                    //System.out.println("frame: "+ _editor.getCaret().isVisible());
                    JInternalFrame f = (JInternalFrame)e.getSource();
            class MyFocusAdaptor extends FocusAdapter{
                public void focusGained(FocusEvent e) {
                    //System.out.println("focus gained");
                    JComponent comp = (JComponent)e.getComponent();
                public void focusLost(FocusEvent e){
                     JComponent comp = (JComponent)e.getComponent();
        (Review ID: 109272)

        Name: ks88420 Date: 09/11/2000

        java version "1.3.0beta_refresh"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta_refresh-b09)
        Java HotSpot(TM) Client VM (build 1.3.0beta-b07, mixed mode)

        The problem can be demonstrated in the same way both under Linux with the 1.3
        version described and under Windows 98 with 1.3 final. 1.2.2 does not exhibit
        the erroneous behavior. Text caret disappears forever and text selection
        becomes invisible after executing the steps to demonstrate this bug. Although
        neither the caret nor selections are visible, they work okay (text can be copied
        and entered), but it is really a huge pain to type without the caret or
        highlight without seeing the selection, obviously.

        This code reproduces the problem:

        import java.awt.*;
        import javax.swing.*;

        public class x extends JFrame
            public static void main(String[] args) throws Exception
                new x();

            public x()
                JTextArea f1 = new JTextArea();
                JTextArea f2 = new JTextArea();


                JDesktopPane cp = new JDesktopPane();

                JInternalFrame if1 = new JInternalFrame();
                JPanel p1 = new JPanel(new GridLayout(1, 1));
                p1.add(new JScrollPane(f1));

                JInternalFrame if2 = new JInternalFrame();
                JPanel p2 = new JPanel(new GridLayout(1, 1));
                p2.add(new JScrollPane(f2));

                if1.setBounds(20, 20, 200, 100);
                if2.setBounds(240, 20, 200, 100);



        It will create a JFrame with two JInternalFrames, each containing a JTextArea.
        Follow these exact steps:
        1. Drag the mouse in the left text area are to highlight text.
        2. Click on the right internal frame's title bar to "activate" it.
           The selection in the left frame will disappear (doesn't happen with 1.2.2)
        3. Now click on the left internal frame's title bar to "activate" it.
        4. Try to highlight text again -- the selection is not visible. Try clicking
           on text areas -- the caret does not appear

        I found that the caret can reappear if you minimize and restore the main
        window. Moreover, I found that you do not even need to highlight test to
        demonstrate the bug. It suffices if you click in the text area in step 1
        and then perform the other steps.

        This bug is really critical if you use internal frames with text areas supposed
        to accept user input, and this is not an uncommon situation.
        (Review ID: 109446)

        Name: yyT116575 Date: 10/19/2000

        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

        In the following test program, try this:

        1. Move all the frames.
        2. get the caret to show in all the frames (in the JTextField).

        On windows NT, it is not possible to get the caret shown again. In windows 98,
        the caret is visible.

        When pressing enter, the ActionListener should be called. this is _not_
        happening on NT and 98.

        if all the frames is on their own layer, there is no problem.

        import java.awt.event.*;

        import javax.swing.*;

        public class InternalFrameTest

        public static void main(String args[])
        JFrame f = new JFrame();
        f.addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
        ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        JTextField field;
        JDesktopPane pane = new JDesktopPane();
        JInternalFrame if1 = new JInternalFrame("Test 1", false, true);
        if1.setSize(100, 100);
        field = new JTextField();
        JInternalFrame if2 = new JInternalFrame("Test 2", false, true);
        if2.setSize(100, 100);
        field = new JTextField();
        JInternalFrame if3 = new JInternalFrame("Test 3", false, true);
        if3.setSize(100, 100);
        field = new JTextField();
        pane.add(if1, JLayeredPane.DEFAULT_LAYER);
        pane.add(if2, JLayeredPane.DEFAULT_LAYER);
        pane.add(if3, JLayeredPane.DEFAULT_LAYER);
        f.setSize(500, 500);

        I have tried to change something in JInternalFrame. It works, but i am not sure
        if this is the "right" solution:

        this code in setSelected(boolean selected):
        if(selected) {
        JRootPane r = getRootPane();
        if (r.getCurrentFocusOwner() != null) {/* do nothing */
        } else if (r.getPreviousFocusOwner() != null) {
        } else {

        change to:
            if (selected) {
        if (r.getCurrentFocusOwner() != null) {
        } else if (r.getPreviousFocusOwner() != null) {
        final Component prev = r.getPreviousFocusOwner();
        SwingUtilities.invokeLater(new Runnable() {
        public void run() {
        } else {


        (Review ID: 109953)


            Issue Links



                svioletsunw Scott Violet (Inactive)
                skonchad Sandeep Konchady
                0 Vote for this issue
                0 Start watching this issue