-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
swing1.1
-
sparc
-
solaris_2.5
-
Verified
Name: akC57697 Date: 04/02/98
The java.awt.swing.text.DefaultCaret.focusGained(...) does not
do the text selection visible.
The doc says:
" .........
Called when the component containing the caret gains
focus. This is implemented to set the caret to visible
if the component is editable, and sets the selection
^^^^^^^^^^^^^^^^^^
to visible.
^^^^^^^^^^^
.........
"
The reason: "setSelectionVisible(true)" is commented in the JDK source code.
-----------------------Example--------------------
import java.awt.swing.text.*;
import java.io.*;
import java.awt.swing.JFrame;
import java.awt.swing.JTextArea;
import java.awt.swing.text.*;
public class testDefaultCaret {
public static void main(String s[]) {
JFrame f = new JFrame();
DefaultCaret caret = new DefaultCaret();
Document doc = new PlainDocument();
try {
doc.insertString(0,"The test string",null);
} catch (Exception e) {}
JTextComponent comp = new JTextArea(doc);
caret.install(comp);
f.getContentPane().add(comp);
f.setBounds(25,25,100,100);
f.setVisible(true);
caret.setVisible(false); // Set caret invisible
comp.setVisible(true);
comp.setEditable(true); // Editable
comp.setSelectionStart(0); // Make a selection
comp.setSelectionEnd(doc.getLength());
// The test
caret.focusGained(new java.awt.event.FocusEvent(f,0));
if (!caret.isSelectionVisible()) {
System.out.println("The selection >"+comp.getSelectedText()+"< is not visible.");
f.dispose();
return;
}
f.dispose();
System.out.println( "OKAY" );
return;
}
}
--------------------------------------------------
Output:
The selection >The test string< is not visible.
======================================================================