dcsimg
Facing some problems with AttributeSet
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Trupti_Mehta
Posted On:   Thursday, May 2, 2002 03:36 AM

Hello Friends, I have created a small editor with differnt features like making text bold, italics, underline, align text, Super/Sub script, Strike, changing font, size, color, etc. I am using JTextPane, HTMLEditorKit, DefaultStyledDocument. I am able to matain all attributes in all the above features i.e if I change the font & then the color, the font also remains. I also have a features of Change Case - Upper or Lower. In this case, what I do is I just call textPane.replaceSelection(textPane.getSelectedText().toUpper()) , and this works perfectly. The problem is: If I have set font o   More>>


Hello Friends,


I have created a small editor with differnt features like

making text bold, italics, underline, align text, Super/Sub

script, Strike, changing font, size, color, etc. I am using

JTextPane, HTMLEditorKit, DefaultStyledDocument.

I am able to matain all attributes in all the above

features i.e if I change the font & then the color, the

font also remains. I also have a features of Change Case -

Upper or Lower. In this case, what I do is I just call

			
textPane.replaceSelection(textPane.getSelectedText().toUpper())
, and this works perfectly.


The problem is:

If I have set font or color or any format mentioned above,

and I select the text & click Upper Case, I loose all the

attributes. I want those attributes to retain & change the

case. The code is as follows :


			
int start = textPane.getSelectionStart();
int end = textPane.getSelectionEnd();

AttributeSet mas = textPane.getCharacterAttributes();
textPane.replaceSelection textPane.getSelectedText().toUpperCase());
textPane.repaint(); // Tried commenting this line
textPane.requestFocus(); // and this line
textPane.setSelectionStart(start);
textPane.setSelectionEnd(end);
textPane.getSelectedText());
textPane.setCharacterAttributes(mas, true);
textPane.repaint();
textPane.requestFocus();



I am stuck up at this point only. I need help urgently.

Can somone let me know where am I going wrong & what

changes should be made to retain the attributes of text.


It would be nice if u can reply me at terry_mehta@hotmail.com

Thanks




Trupti
   <<Less
About | Sitemap | Contact