| | |
I've tried everything...setting font of selected text
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I've been trying to do this for weeks now, and can't seem to get it to work. I have a JTextPane called textArea2, and I have a variable called doc that gets the document from the textpane. I want to get the selected text but I can't get no code to work. I've posted in a lot of forums and no one will help me.
This is the code I have so far:
I get an error message saying cannot find symbol, method setcharacter attributes(and ithen it lists the arguments)
This is the code I have so far:
Java Syntax (Toggle Plain Text)
public void processBoldText() { MutableAttributeSet mas = new SimpleAttributeSet(); Font f = new Font ("SansSerif", Font.BOLD, 20); StyleConstants.setBold(mas,f.isBold()); int offset = textArea2.getSelectionStart(); int end = textArea2.getSelectionEnd(); int length = end - offset; doc.setCharacterAttributes(offset,length,mas,false); }
I get an error message saying cannot find symbol, method setcharacter attributes(and ithen it lists the arguments)
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
This is what you can do
The fault is that you did not set a styled document type
I hope this helps you
Richard West
This is what you can do
Java Syntax (Toggle Plain Text)
StyleContext sc = new StyleContext(); DefaultStyledDocument dse = new DefaultStyledDocument(sc); textarea2.setDocument(dse); public void processBoldText( ) { MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setBold(mas, true); int offset = textarea2.getSelectionStart(); int end = textarea2.getSelectionEnd(); int length = end - offset; dse.setCharacterAttributes(offset,length,mas,false); }
The fault is that you did not set a styled document type
I hope this helps you
Richard West
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Server Crash you said "I had a find, find next , find and replace method that worked fine on the JTextArea, but it does really weird things on the JTextPane"
You know something i had the same problem with this find/replace function of mine but here is the funny thing,
I have two computers both running on windows 98 and both installed with java sdk
1.4.2 but my program runs perfectly on one computer but does weird things on the other computer. I really don't know why but i think this is rather weird, don't you think so?
Richard West
Server Crash you said "I had a find, find next , find and replace method that worked fine on the JTextArea, but it does really weird things on the JTextPane"
You know something i had the same problem with this find/replace function of mine but here is the funny thing,
I have two computers both running on windows 98 and both installed with java sdk
1.4.2 but my program runs perfectly on one computer but does weird things on the other computer. I really don't know why but i think this is rather weird, don't you think so?
Richard West
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Some Simple Console App Questons (Java)
- Next Thread: Creating data access layer in java
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






