| | |
help with regex...and marking up text in JTextpane with html
![]() |
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Solved Threads: 0
having trouble getting this match and replace to work, im trying to just find a word and put html bold tags around it on the button click and put that text into a new jtextpane. anyone have any suggestions??? any help would be most appreciative
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import java.util.StringTokenizer; import java.util.regex.*; import javax.swing.*; public class Assn4 extends JFrame{ private JTextPane textPane1, textPane2; private JButton copyButton; ; public Assn4() { super( "Code Format" ); Box box = Box.createHorizontalBox(); StringBuffer buffer1 = new StringBuffer( "Testsearchingstring" ); textPane1 = new JTextPane(); textPane1.setText( buffer1.toString() ); box.add( new JScrollPane( textPane1 ) ); String str = "searching"; Pattern pattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher( buffer1.toString() ); if (matcher.matches() ) { String result = matcher.replaceAll("<b>$1</b>"); textPane1.setText( result ); } copyButton = new JButton( "Copy >>>"); copyButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { textPane2.setText( textPane1.getText() ); } } ); box.add( copyButton ); textPane2 = new JTextPane(); textPane2.setEditable(true); box.add( new JScrollPane( textPane2 ) ); Container container = getContentPane(); container.add( box ); this.setLocationRelativeTo( null ); this.setSize( 600, 300 ); this.setVisible( true ); } public static void main( String args[] ) { Assn4 application = new Assn4(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); } }
![]() |
Similar Threads
- Tutorial: Forms: styling text fields with CSS and HTML (Site Layout and Usability)
- Regular expression class with child/parent (C#)
- Read contents of external text file into html page (HTML and CSS)
- print selected text in a html page (JavaScript / DHTML / AJAX)
- Indent the C text in vb.net (VB.NET)
Other Threads in the Java Forum
- Previous Thread: purpose of exception handling 'finally' clause
- Next Thread: Random Number Generator
| 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





