JDK-4408683 : Caret not visible using JWindow
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-01-26
  • Updated: 2001-01-31
  • Resolved: 2001-01-31
Related Reports
Duplicate :  
Description

Name: ssT124754			Date: 01/26/2001


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)


The following code demonstrates a simple application containing a text.
Applications based on a JFrame behave as expected. Applications based on
JWindow do not show a caret in JTextArea or JTextField. Although the caret
never shows up, you can still edit text, and you can still select your position
using arrow keys or the mouse.

package demo;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Window;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JWindow;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class CaretDemo extends JPanel {
  
	public CaretDemo() {
		setLayout(new BorderLayout(5,5));
		setBorder(new EmptyBorder(10,10,10,10));
		
		JTextField textField = new JTextField("Where is the JTextField
caret?");
		add(textField, BorderLayout.NORTH);

		JTextArea textArea = new JTextArea("Where is the JTextArea
caret?");
		add(textArea, BorderLayout.CENTER);
	}
  
  public static void main(String [] args) {
  	
 // JFrame parent = new JFrame();
    JWindow parent = new JWindow();
  	
		parent.setBounds(100, 100, 600, 200);

		Container container = parent.getContentPane();
		container.add(new CaretDemo());
		
		parent.setVisible(true);
	}
}
(Review ID: 115794) 
======================================================================

Comments
EVALUATION This is happening because by design Window's are not focusable. As of 1.4 they can be made focusable, in which case JTextComponents will work correctly. Unfortunately a JWindow created throught the nullary constructor is not focusable, instead you need to create one with a valid, focusable, parent. I am closing this as a duplicate of 4290675 which is the bug covering the new focus architecture. scott.violet@eng 2001-01-30
30-01-2001