increasing font size
Hello all,
I have a JEditorPane and i wish to increase the font size of the html content that it holds so far i am at this point and it doesn't seem to work:
HTMLEditorKit size =new HTMLEditorKit();
String bigger = size.FONT_CHANGE_BIGGER;
displayEditorPane.setEditorKit(size);
displayEditorPane.setEditorKitForContentType(bigger, size);
What is wrong with the above?
Is there any other way i can increase font size?
All help will be appreciated. Thank you. :)
[555 byte] By [
abshirf2a] at [2007-11-26 23:45:51]

# 1
Perhaps you should send an excecutable code example so that we can test it..Also you say: String bigger = size.FONT_CHANGE_BIGGER;, bigger than what size? Im not to good at HTMLEditorKit but I think that might be the problem..Also why not use the setFont()?
# 2
I used setFont() and it doesn't work!
Font f = new Font("Big", Font.PLAIN, 20);
displayEditorPane.setFont(f);
No idea why!
I named the string "bigger" just to let me know that its bigger than the default size.
I just a way to make the font size bigger for a JEditorPane which is not editable.
# 3
Try the following and see what you get:for (int i = 0; i < 5; i++) System.out.println( size.FONT_CHANGE_BIGGER);
# 4
>I used setFont() and it doesn't work!
Thats odd.. I tryed it with this verry small example, and it works just fine, try it out.
import java.awt.Font;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
public class TestSetSize {
public static void main(String[] args) {
JFrame frame = new JFrame("Test");
JEditorPane pane = new JEditorPane();
Font f = new Font("Big",Font.PLAIN,22);
pane.setFont(f);
frame.add(pane);
frame.setSize(200,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
So its probably something else with htmleditorkit.. Please post an small example code so we can see the rest.
# 5
I got this when i tried:
for (int i = 0; i < 5; i++)
System.out.println( size.FONT_CHANGE_BIGGER);
html-font-bigger
html-font-bigger
html-font-bigger
html-font-bigger
html-font-bigger
My code is quite big thats why i dont think it will be a good idea to post it but here is some of it:
public class Final{
public Final(){
// Set up page display.
displayEditorPane = new JEditorPane();
displayEditorPane.setContentType("text/html");
displayEditorPane.setEditable(false);
displayEditorPane.addHyperlinkListener(this);
displayEditorPane.setSize(650, 480);
//displayEditorPane.setLocation(200,100);
displayEditorPane.setVisible(true);
}
The bit i try to implement the font increase is the actionperformed() method when a option is chosen from menu:
public void actionPerformed(ActionEvent event) {
String action = event.getActionCommand();
Object objectSource = event.getSource();
if(action.equals("Add Tab")){
System.out.println("Yeah you pressed tab from Display class");
Container.CreateTab();
}
if(action.equals("Close Tab")){
System.out.println("Yeah you pressed Close tab from Display class");
Container.closeTab();
}
if(action.equals("Increase Size")){
System.out.println("Yeah you pressed Increase Size from Display class");
/* for(int i=0; i<100; i++){
Font f = new Font("Big", Font.PLAIN, (20+i));
displayEditorPane.setFont(f);
displayEditorPane.repaint();
displayEditorPane.setVisible(true);
}*/
/*
displayEditorPane.repaint();
displayEditorPane.revalidate();*/
HTMLEditorKit size = new HTMLEditorKit();
for (int i = 0; i < 5; i++)
System.out.println( size.FONT_CHANGE_BIGGER);
/* displayEditorPane.setEditorKit(size);
displayEditorPane.setEditorKitForContentType(bigger, size);*/
// Container.setComponentsFont(Container.myContainer, f);
}
}
Hope you can help. :)
# 6
Ive noticed now that your using setcontenttype("text/html"). Im not so good in this particular area but by setting it to that you choose to edit the incoming inputstream as html. In other words what you will recive while using this is purely text and html code(page sourcecode).
Im not sure that is the best way to go on with an webbrowser, try out the displayEditorPane.setpage(URL); instead.
Also it is the setcontenttype("text/html") that makes it so hard(almost impossible) to change the size.
Im afraid I cant help your much more than suggesting that you start using the setPage metod instead..
Also if you wanna add an option like view page sourcecode then setcontentype is the right way to go.
# 7
I didn't know that! Will try displayEditorPane.setpage(URL); .But generally should the set font work if i do it like you said prigas by setting page to URL.What other way is there to increase size of text in a JEditorPane?
# 8
Well there is anotherway to do it, I use this in my own textedior that Ive made:new StyledEditorKit.FontSizeAction(text, size).actionPerformed(null);Im not sure if its gonna work, but its worth an try.
# 9
Thank you very much for your help prigas. It didn't work but i think its my code thats the problem i'm going to have to completely restructure it because its stoping me from increasing he font size in my web bowser i am also having troible adding tabs to it!
Its problems galore! :)
I'm going to restructure if thats don't work, will post code here so i can some help and pointers on where i am going wrong.
Oh by the way, a constructor that creates a JEditorPane will create and object if its instantiated like this: Display browser = new Display();
, right? Will it matter if in the constructor that i have buttons and panels, or do i have to keep them separate to have an object that is a JEditorPane?
Thanks
# 10
> Thank you very much for your help prigas. It didn't
> work but i think its my code thats the problem i'm
> going to have to completely restructure it because
> its stoping me from increasing he font size in my web
> bowser i am also having troible adding tabs to it!
> Its problems galore! :)
>
> I'm going to restructure if thats don't work, will
> post code here so i can some help and pointers on
> where i am going wrong.
>
> Oh by the way, a constructor that creates a
> JEditorPane will create and object if its
> instantiated like this: Display browser = new
> Display();
, right? Will it matter if in the
> constructor that i have buttons and panels, or do i
> have to keep them separate to have an object that is
> a JEditorPane?
>
> Thanks
If your Display class is a 'browser', than you can put anything you want in the constructor to construct ... or in other methods that the constructor calls.
# 11
Hello all,
I am making a browser and i want to be able to increase the font size for my browser the way IE and Firefox do. I have the following:
System.out.println("Current Font: " + displayEditorPane.getFont().toString());
Font f = new Font("Big", Font.PLAIN, 70 );
displayEditorPane.selectAll();
displayEditorPane.setFont(f);
displayEditorPane.repaint();
Container.tabbedPane.getSelectedComponent().repaint();
System.out.println("New Font: " + displayEditorPane.getFont().toString());
where the diplayEditorPane is a JEditorPane. I get the following:
Current Font: javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12]
New Font: java.awt.Font[family=Dialog,name=Big,style=plain,size=70]
The font size doesn't change for my JEditorPane but the images it shows reloads. Also the first font is javax.swing.plaf.FontUIResource and then it changes to java.awt.Font? Anyone know why this happens.
How else can i increase font size without using setFont() because this doesn't seem to work!?
