append a JTextPane's content to another one?

hi everyone,

Things associated with text components are so complex, not as simple as I thought. My time is shortening :(. Please show me an effective way to append a JTextPane's content to another one. Every attributes must be kept after appended. Please help me or just give me a keyword so I can search for in on Sun site. :)

Thank you.

Message was edited by:

Everlearn

[404 byte] By [Everlearna] at [2007-10-3 0:38:31]
# 1
Did you already try to work with the document you get by using getStyledDocument()?
pholthuizena at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...
# 2

Well, you will probably need to loop through all the elements in the Document and insert the text and attributes associated with each element. This is how you get the root element:

Element root = component.getDocument().getDefaultRootElement();

Read the element API for more information.

Here's something that might help you out. Check out this demo program that comes with the JDK:

j2sdk1.4.2\demo\jfc\Stylepad

Double click on the Stylepad.java file to start the demo.

Click on the "debug" menu and then "Show Elements".

This will display a tree showing the structure of your Document. If you can figure out and understand how the JTree is built then you should be able to iterate through your Document and pass the structure, one element at a time.

camickra at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...
# 3
thank you, camickr. I just tried your "Element" keyword and your "getDefaultRootElement()" with some references from Sun and it was done. Fairly easy, thanks again.
Everlearna at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...
# 4

please help me a bit more, camickr, I have tried to change my button margin, and frame font but I couldnt. Dont know what the 2 arguments are. If I need further working with my UI, I shouldnt ask you whenever I have problem. Do you have any reference for my later use, just a map of key/value pairs for the put() method is enough.

thank you.

Edit: I have checked the Button source class and couldnt find a font attribute, just wonder where it is...

Everlearna at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...
# 5

Start a new posting for questions on a different topic for a better response from people in the forum.

> I have tried to change my button margin,

button.setMargin( new Insets(0, 50, 0, 50) );

> Dont know what the 2 arguments are

Not sure what you are talking about

> just a map of key/value pairs for the put() method is enough.

If you are talking about the UIManager.put(...) method then check out this program:

http://www.discoverteenergy.com/files/ShowUIDefaults.java

camickra at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...
# 6

I meant to change margin for all buttons in my program, so the setMargin() method may be not good, I just wanna use the put() method like you used put( "Button.font", new FontUIResource(..) ) for changing all buttons' font.

The second thing I wanna ask you is a table of argument pairs for the UIManager.put( key, value ) method, like this ( or something similar ) :

__key_|_value_|

Button.font........|..FontUIResource...|

Buton.margin...|.........?............|

......?........|.........?............|

||

The problem is that I dont know all the keys and the appropriate value for each.

I will start my new questions on a new post, thanks.

Everlearna at 2007-7-14 17:32:29 > top of Java-index,Desktop,Core GUI APIs...