JTextPane: Workaround for invisible text with hanging indents?



Hi all,

I have a hanging indent requirement for paragraph formatting:
<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/StyleConstants.html#FirstLineIndent>

"The amount of space to indent the first line of the paragraph. This value
may be negative to offset in the reverse direction. The type is Float and
specifies the size of the space in points."

A search of Sun's bug database for [set]FirstLineIndent indicates that Sun
has fixed a number of bugs related to rendering negative first line
indents. Does the code I've written below demonstrate another rendering
bug? I'm typing invisible text on multiple platforms with the latest
stable JDK and Mustang beta:


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

public class InvisibleText extends JFrame {

public InvisibleText() {
JTextPane tp=new JTextPane();
SimpleAttributeSet attrs=new SimpleAttributeSet();
StyleConstants.setFirstLineIndent(attrs, -150.0f);
StyleConstants.setLeftIndent(attrs, 150.0f);
tp.setParagraphAttributes(attrs, true);

JScrollPane sp=new JScrollPane(tp);
sp.setPreferredSize(new Dimension(300, 200));
getContentPane().add(sp);
}

public static void main(String[] args) {
InvisibleText frame=new InvisibleText();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}


While typing text finally appears at the left indent position of
subsequent lines.

Assuming my code correctly invokes this API, can anyone come up with a
workaround to make the text appear while it is typed?

Many thanks,
Adam
.



Relevant Pages

  • Re: Paragraph Not Centered Correctly
    ... Definitely no indent. ... In the body of the doc, with page setup and paragraph formatting identical ... This is probably why the centering is wrong, ... some reason it thinks there's a margin or indent at 5.75. ...
    (microsoft.public.word.docmanagement)
  • Re: set different indents for paragraphs
    ... This program sucks for layout. ... Most paragraph formatting applies to the entire text ... >> the bullet paragraph, second line to be indent. ...
    (microsoft.public.powerpoint)
  • Re: Turn off paragraph indenting
    ... What you want is called a "Hanging Indent" & isn't to be had by the Tab key. ... It's a paragraph formatting attribute which can be applied in a few ways: ...
    (microsoft.public.word.newusers)
  • Re: Inserting picture causes paragraph formatting to be ignored.
    ... first line set at your indent measurement. ... > when I insert a picture into a publisher page -- say ... > th right of the picture, the paragraph formatting is ... > How can I insert the picture and preserve the paragraph ...
    (microsoft.public.publisher)
  • Re: Late Dates incorrect after indenting under Summary Task
    ... about task 11's predecessor, but then I tried it both ways - no predecessor ... > Don't indent it under the summary until you've added all the tasks. ... > 2 Start Milestone #1 ... >> I'm not aware of any "bug" like you're describing. ...
    (microsoft.public.project)