you need to change actual content of the document being displayed, the font used is defined by the html
Main Topics
Browse All TopicsHi Experts
I am using JEditiorPane to display HTML I want to be able to change the font and size of the text displayed by the web page. I know this is possible in a JTextArea.
I am using the code below for my ActionListener the code executes but does not have any effect on the web page displayed.
public void actionPerformed(ActionEven
//This method is called whenever an event occurs on a component
//that has registered an ActionListener
//Read the action command
String c = event.getActionCommand();
System.out.println(c); //Print the action command for demonstration purposes
if("Font Info".equals(c)){
//Show font information
String msg = "Font Name:" + browserPane.getFont().getN
+ "\nFont Size:" + browserPane.getFont().getS
JOptionPane.showMessageDia
}
else if("New tab".equals(c)){
//Create new tab
createNewTab();
}
else if("Exit".equals(c)){
//Exit program
System.exit(0);
}
else if("Helvetica".equals(c)){
//Set the font to Helvetica
browserPane.setFont(new Font("Helvetica", Font.PLAIN, browserPane.getFont().getS
}
else if("Courier".equals(c)){
//Set the font to Courier
browserPane.setFont(new Font("Courier", Font.PLAIN, browserPane.getFont().getS
}
else{
//Resize the font
browserPane.setFont(new Font(browserPane.getFont()
}
}
Does anyone know how to manipulate the font and font size of a web page displayed in a JEditorPane?
Thanks
Clive
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try this,
//define a custom custom htmleditor kit
class CustomHTMLEditorKit extends HTMLEditorKit{
private static final ViewFactory defaultFactory = new javax.swing.text.html.HTML
public View create( Element elem ){
Object o = elem.getAttributes().getAt
if (o instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag) o;
if (kind == HTML.Tag.CONTENT) {
return new CustomFontInlineView( elem ); //return the custom font view
}
}
return super.create( elem ) ;
}
} ;
public ViewFactory getViewFactory(){
return defaultFactory ;
}
}
//define the custom font view
class CustomFontInlineView extends InlineView{
public Font getFont(){
return new Font( "your font spec here" ) ;
}
}
//and finally set the custom editor kit to the editor pane
youJEditorPane.setEditorKi
Business Accounts
Answer for Membership
by: CEHJPosted on 2007-04-24 at 15:16:08ID: 18970025
For a given document you could try to xml-ize it and use xslt
667
http://www.xml.com/lpt/a/1