Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JTextPane +insert text,image with style

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i try to insert text from one text pane to secone with style
My problems
- after i insert image text style change to normal
- i finde solution to switch off line wrap but i don't know how
go to next line whene i am a the end of textpane i can't switch on
auto line wrap in JTextPane becouse it do strange things withe style text

Sorry for my english

MY Code



[ June 05, 2007: Message edited by: argol diomolpol ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by argol diomolpol:
i try to insert text from one text pane to secone with style
My problems
- after i insert image text style change to normal



This code is doing some crazy things. For example, you seem to be keeping track of all of the style information from the first Document manually via a CaratListener. In fact, your problem likely lies in this part of your code.

But why bother to do that at all? The Document itself keeps track of style information. To copy from one Document to the other all you need to do is something like this:



Where appendDoc is implemented like this:





- i finde solution to switch off line wrap but i don't know how
go to next line whene i am a the end of textpane i can't switch on
auto line wrap in JTextPane becouse it do strange things withe style text



Line wrap doesn't have much to do with style. I'm not sure what you're talking about here.
 
argol diomolpol
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for great piece of code
but now i have problem with inserting to icons in a row
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by argol diomolpol:
but now i have problem with inserting to icons in a row



Perhaps if you were to tell more details we could help.
 
argol diomolpol
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whene i try insert 2 or more icons in a row caret stay in positon after first icon
I can insert 2 or more icons only whene i change style after previous
icon(change style)icon etc..
Whene i try to insert icon by textPane.insertIcon(icon) it is no problem
with inserting icons in a row but it change style of text to regural
and don't know how change it to previous style
 
argol diomolpol
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is look like this method block insert 2 or more icones in a row
but i don't know how to fix it
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by argol diomolpol:
whene i try insert 2 or more icons in a row caret stay in positon after first icon
I can insert 2 or more icons only whene i change style after previous
icon(change style)icon etc..
Whene i try to insert icon by textPane.insertIcon(icon) it is no problem
with inserting icons in a row but it change style of text to regural
and don't know how change it to previous style



Actually, are you sure about textPane.insertIcon() working? It didn't work for me when I just tried it. The first call worked, but the second (with the same icon) didn't. This makes me think that this might be Sun's bug, not yours.

Anyway, it seems like the way you are adding icons to 'doc' is needlessly complex, but starting with your code one way to allow two icons in a row is to change this:

Atr = textPane.getInputAttributes();
set = doc.getStyle("icon");
set(set);
doc.insertString(doc.getLength()," ",Atr);

to this:

Atr = textPane.getInputAttributes();
set = doc.getStyle("icon");
set(set);
SimpleAttributeSet atr2 = new SimpleAttributeSet(set);
atr2.addAttribute("timestamp", new Long(System.currentTimeMillis()));
doc.insertString(doc.getLength()," ",atr2);

The idea is that the style of the two icons will be different (because of the bogus "timestamp" attribute) and therefore will not be combined.
 
argol diomolpol
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but it loses styles
for exmaple i have bold after i insert icone it's change to regural

i have one more question it is possible to add Style to AttributeSet
becouse i need to send AttributeSet in byte array or string over network i
i try somthing like that but the size of byte array was to big from 13KB-300KB(if was a lot of styles in text)


My second option is to use style which are in addStylesToDocument() method
I can recognize style from string for example
i send String d = bold#italic#underline over network reciver it
and split it to table String [] dd = d.split("#") but whene i insert text

text will be one only bold or italic or underline it won't be italic and bold how to solve it
[ June 11, 2007: Message edited by: argol diomolpol ]
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by argol diomolpol:
but it loses styles
for exmaple i have bold after i insert icone it's change to regural



Well you could always try something like:

SimpleAttributeSet atrCopy = new SimpleAttributeSet(Atr);
doc.insertString(doc.getLength()," ",atr2);
textPane.getInputAttributes().addAttributes(atrCopy);


i have one more question it is possible to add Style to AttributeSet



Well, a Style is an AttributeSet, in the same way that a StyledDocument is a Document. So I'm not sure exactly what you mean, but something like myAttributeSet.addAttributes(myStyle) or myAttributeSet.setResolveParent(myStyle) might do what you want.

becouse i need to send AttributeSet in byte array or string over network i
i try somthing like that but the size of byte array was to big from 13KB-300KB(if was a lot of styles in text)



There are ways to transmit AttributeSets over the network, but it seems like too much trouble to me. If nothing else works, wouldn't it be easier to just insert some whitespace text between any two abutting icons?
 
argol diomolpol
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whata about add styles to AttributeSet i do somthin like this
Whene i click one of JToggleButons i add to string names of styles which
i deklar in addStylesToDocument method

etc..

Then i split this string to tables

String t[] = text.split("#");
String s[] = still.split("#");

for fist time i append to doc2


for to rest:
first i check which styles are to start style the differen beetwen
s.lenght - t.lenght give to where is start style

and append to doc like before

But the problem is tha this still String grow all the time so it the size of this will grow too i try to cut this string but the result was always bad

Maby there is better way to do this

[ June 13, 2007: Message edited by: argol diomolpol ]
[ June 13, 2007: Message edited by: argol diomolpol ]
reply
    Bookmark Topic Watch Topic
  • New Topic