Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Help: Attributes are ignored
Hi,

I want to print out a String with certain attributes. Therefore I´m
adding an StyledDocumentObject into an JTextArea.
Now "strange" things happen: the text is ("This is only a Test")
printed out on the screen but the attributes are ignored. I used the
getAttributeCount() method to count the attributes in the attribute
set and the number is as I expected.


The source code looks as follows:
--------------------------------------------------------------------
public class Test
{
protected JTextArea termArea;

termArea = new TextAreaCtl();
termArea.setEditable(false);

DefaultStyledDocument styledDoc = new DefaultStyledDocument();
SimpleAttributeSet mySimpleSet = new SimpleAttributeSet();
System.out.println("ANZATTR :"+ mySimpleSet.getAttributeCount());

StyleConstants.setBold(mySimpleSet, true);
StyleConstants.setForeground(mySimpleSet, Color.green);
System.out.println("ANZATTR :"+ mySimpleSet.getAttributeCount());

try
{
System.out.println("ANZATTR: "+ mySimpleSet.getAttributeCount());
styledDoc.insertString(0, "This is only a Test!", mySimpleSet);
}
catch(BadLocationException e) {System.out.println("Error");}

termArea.setDocument(styledDoc);
}



--------------------------------------------------------------------
The output is:

0
2
2
--------------------------------------------------------------------


Why are the changes in mySimpleSet ignored?

How can I overcome this?

kind regards,

Peter




Report this thread to moderator Post Follow-up to this message
Old Post
Peter Theissen
12-17-04 01:57 PM


Re: Help: Attributes are ignored
At 12/17/2004 3:26:56 AM, Peter Theissen wrote:

> Hi,
>
> I want to print out a String with certain attributes. Therefore I´m
> adding an StyledDocumentObject into an JTextArea.
> Now "strange" things happen: the text is ("This is only a Test")
> printed out on the screen but the attributes are ignored. I used the
> getAttributeCount() method to count the attributes in the attribute
> set and the number is as I expected.
>

A JTextArea cannot display text with attributes.  From the javadoc for
JTextArea:

A JTextArea is a multi-line area that displays PLAIN TEXT. (emphasis
added).

You need to use a JEditorPane instead.

--
Jim McMaster
mailto:jim.mcmaster@comcast.net


Report this thread to moderator Post Follow-up to this message
Old Post
Jim McMaster
12-24-04 02:04 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:34 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.