-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
Name: rmT116609 Date: 05/19/2003
FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Using JTextPane's insertIcon(...) method when the instance of JTextPane on which the method is being invoked has earlier had setEditable(false) invoked, results in no icon being inserted.
One is still able to insert an icon via a Style and insertString on the JTextPane instance's document though -- so at the very least there's an inconsistency, and more likely this is a bug with insertIcon.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
i.Compile the class included in the source code below
ii. run
iii. click the "insert icons" button - note behaviour
iv. turn off editable via the check box;
v. click "insert icons" again; note behaviour
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
both icons should be inserted whether the text pane is editable or not.
ACTUAL -
both icons were inserted when editable was true, but not when false.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/**
* Class demonstrates functionality broken under osX 1.4.1_01 -- that
* inserting an icon either via JTextPane's insertIcon() or sneaking
* it in through a style on the text pane's document's insertString
* doesn't work if the text pane is not editable.<br>
*
* This function is also partially broken under Windows 1.4.2_beta --
* insertIcon() doesn't work if the instance is not editable.
*/
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
import javax.swing.text.*;
public class TPaneIconUgh
implements ActionListener {
protected ImageIcon someIcon;
protected JTextPane textPane;
public TPaneIconUgh () {
this.buildFrame().show();
}
protected JFrame buildFrame () {
JFrame jf = new JFrame("JTextPane icon bugs");
Dimension d = new Dimension(400, 300);
JButton jb = new JButton("Insert icons");
JPanel pane = new JPanel();
JCheckBox cb = new JCheckBox("text pane is editable");
JScrollPane sp = null;
try {
URL u = new URL("http://java.sun.com/docs/books/tutorial/images/TOCIcon.gif");
this.someIcon = new ImageIcon(u);
} catch (Exception e) {
System.err.println("Exception in grabbing image icon: " + e);
}
jf.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent e) {
System.exit(0);
}
});
this.textPane = new JTextPane();
cb.setSelected(true);
sp = new JScrollPane(this.textPane);
sp.setMinimumSize(d);
sp.setPreferredSize(d);
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
pane.add(cb);
pane.add(sp);
pane.add(jb);
jf.getContentPane().add(pane);
jf.pack();
jf.setLocationRelativeTo(null);
cb.addActionListener(this);
jb.addActionListener(this);
return jf;
}
protected void doIconInserts () {
StyledDocument doc = this.textPane.getStyledDocument();
Style style = doc.addStyle(null, null);
StyleConstants.setIcon(style, this.someIcon);
try {
this.textPane.insertIcon(this.someIcon);
doc.insertString(doc.getLength(),
" the icon should have just been inserted ",
this.textPane.getCharacterAttributes());
doc.insertString(doc.getLength(),
" TEXT SHOULD BE IGNORED IN FAVOUR OF ICON ",
style);
doc.insertString(doc.getLength(), "\n---\n",
this.textPane.getCharacterAttributes());
} catch (Exception e) {
System.err.println("Exception in inserting text and icons: " + e);
}
}
/**
* ActionListener implementation
*/
public void actionPerformed (ActionEvent ae) {
if (ae.getSource() instanceof JCheckBox) {
this.textPane.setEditable(((JCheckBox)ae.getSource()).isSelected());
} else {
this.doIconInserts();
}
}
static public void main (String args[]) {
new TPaneIconUgh();
}
}
---------- END SOURCE ----------
(Review ID: 185990)
======================================================================
- duplicates
-
JDK-4689119 JTextPane does not allow insert of components when JTextPane is not editable
-
- Resolved
-