Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default Hi i made a browser but cant configure zoom function

    Im pretty lost on configuring zoom function, var name on html reader is JEditorPane, and i want a function to zoom in and out by pressing shift and + to zoom in, and shift and - to zoom out, thats fine i know how to use keyevent but i dont know a way to actually zoom in and out of what the user see on the pane, any help woud be greatly apreciated :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    By zooming do you mean changing the font size of the text that is being displayed?

  3. #3
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    i mean similiar to firefox's inbuildt zoom, when you press Ctrl and adjust the mouse wheel you zoom in and out, and then not just text get larger but pictures and frames to, but if thats hard to manage edit text size is bether than nothing.

    But i wanted to have shift and +/- instead, its just the zoomin im stuck on, it didnt work to change size of displayEditorPane, so yes, im pretty stuck =(
    Last edited by tom99; 10-04-2010 at 04:31 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    What happens when you "zoom"?
    How does Firefox change the display to give the zoom effect?
    Does it use a larger Font? What else?
    What is displayed in the JEditorPane? Is it only text or what?

  5. #5
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    When you zoom on firefox it zoom in on Left marrow of the screen, i guess it create a rectangular camera view on middle Y cord then place it at 0 x coord, all the way to the left and increment cameraview with some pixels eachtime you touch mouse wheel.

    on my browser the JEditorpane display Html and php aswell as some picture formats. but im happy with increased text size instead of zoom in, to zoom in on other things woud just not be relevant (But a bit more fancy and prefered) :)

    Also it dont need to be exactly like the zoom function on firefox, just something similiar. if it just zoom to center of the JEditorpane thats even bether!
    Last edited by tom99; 10-04-2010 at 05:31 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    If the contents of the JEditorPane is html. HTML has <FONT tags that control the font size. Can you change the contents of the FONT tags and redisplay the new HTML?

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by tom99 View Post
    Im pretty lost on configuring zoom function, var name on html reader is JEditorPane, and i want a function to zoom in and out by pressing shift and + to zoom in, and shift and - to zoom out, thats fine i know how to use keyevent but i dont know a way to actually zoom in and out of what the user see on the pane, any help woud be greatly apreciated :)
    In your JEditorPane override the paintComponent( ... ) method like this:

    Java Code:
    	protected void paintComponent(Graphics g) {
    		Graphics2D g2d= (Graphics2D)g;
    	
    		g2d.scale(zoom, zoom);
    		
    		super.paintComponent(g2d);
    	}
    'zoom' is a double type value > 1 means larger painting, < 1 smaller painting.

    kind regards,

    Jos

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    Thanks Jos. I should keep quiet more often and learn things.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Norm View Post
    Thanks Jos. I should keep quiet more often and learn things.
    Mwah, I don't know much about Swing either but recently I've been playing a bit with affine transforms (supported by Graphics2D objects) so I knew how to solve this ... ;-)

    kind regards,

    Jos

  10. #10
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    When i adjusted the zoom var befor i launch browser it does nothing, i also tryed to make it increase zoom after couple of sec when the app had started but still nothing.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by tom99 View Post
    When i adjusted the zoom var befor i launch browser it does nothing, i also tryed to make it increase zoom after couple of sec when the app had started but still nothing.
    You didn't implement it correctly then; I did the same and it works perfectly; show us some (relevant) code.

    kind regards,

    Jos

  12. #12
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    private double zoom = 12;

    protected void paintComponent(Graphics g) {
    Graphics2D g2d= (Graphics2D)g;

    g2d.scale(zoom, zoom);

    super.paintComponents(g2d);
    }

    This dont work, it compile but nothing happened to JEditorPane whatever i changed zoom to it didnt work.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by tom99 View Post
    private double zoom = 12;

    protected void paintComponent(Graphics g) {
    Graphics2D g2d= (Graphics2D)g;

    g2d.scale(zoom, zoom);

    super.paintComponents(g2d);
    }

    This dont work, it compile but nothing happened to JEditorPane whatever i changed zoom to it didnt work.
    If that method wants to override the paintComponent( ... ) method in the JEditorPane you should extend that class and put this method in there. I suspect that you put that method in any (i.e. wrong) class.

    kind regards,

    Jos

  14. #14
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    I only got one class, do i need to extend it still ?

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by tom99 View Post
    I only got one class, do i need to extend it still ?
    You need to extend the JEditorPane class and put that method in it. This is a skeleton of the code:

    Java Code:
    public class MyEditorPane extends JEditorPane {
    
       // all constructors you need here that call their super( ... )
    
       // the paintComponent( ... ) method here
    }
    otherwise there is no way for my paintComponent( ... ) method to call the appropriate paintComponent( ... ) method in the JEditorPane ... the rest of your code (in your other 'single' class) uses a MyEditorPane just as it used a JEditorPane object.

    If you want to, you can even extend the JEditorPane class with an anonymous class:

    Java Code:
    JEditorPane pane= new JEditorPane() {
       // the paintComponent( ... ) method here
    }
    ... but then you have to fiddle a bit with that 'zoom' variable ...

    kind regards,

    Jos
    Last edited by JosAH; 10-05-2010 at 07:16 PM.

  16. #16
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    I cant make it work im using anonymous innerclass.

    do i need to do anything further with the pane ?
    under main method or can i just have the call superclass assignment under main method and wont need anything else?

    In my source i got this to zoom, and im complete questionmark why it wont do anything.
    I got zoom as global var and got a function to decrease and increase it by 25, but no zoom.

    public class MyEditorPane extends JEditorPane {
    protected void paintComponent(Graphics g) {
    Graphics2D g2d= (Graphics2D)g;
    g2d.getBackground();
    g2d.scale(zoom, zoom);
    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONAL METRICS,
    RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    AffineTransform old=g2d.getTransform();
    super.paintComponents(g2d);
    g2d.setTransform(old);
    }

    // all constructors you need here that call their super( ... )

    // the paintComponent( ... ) method here
    }
    Last edited by tom99; 10-06-2010 at 01:38 PM.

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Show us all your code (in [code] ... [/code] tags so we can read it).

    kind regards,

    Jos

  18. #18
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    As you can see it will run but zoom will not work functionally.
    i was wondering if you could help me on this, woud you also know how you could implement an plugin loader ? That means if its not to much to ask for. thnx in advance :D
    Last edited by tom99; 10-06-2010 at 05:24 PM.

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    You're not doing anything with the class MyEditorPane; change this line:

    Java Code:
    displayEditorPane = new MyEditorPane();
    kind regards,

    Jos

  20. #20
    tom99 is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    Where do i add that ? if i put it on display page i get a error on displaying sites, and it dont allow me to put it under the main method.

    If i put it right under the constructor it run smoothly but still nothing.
    Last edited by tom99; 10-06-2010 at 03:57 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. How to simulate browser CTRL+F function
    By crisfromnova in forum SWT / JFace
    Replies: 1
    Last Post: 09-14-2010, 03:41 PM
  2. Replies: 13
    Last Post: 08-30-2010, 08:55 PM
  3. How to Zoom in and Zoom out TYPE_USHORT_565_RGB image
    By Santhoshkumarp in forum AWT / Swing
    Replies: 0
    Last Post: 08-07-2010, 03:39 PM
  4. Java Zoom in and Zoom out?
    By ps20090 in forum Java Applets
    Replies: 2
    Last Post: 09-18-2009, 01:04 PM
  5. No class made
    By ChuckLS in forum New To Java
    Replies: 1
    Last Post: 04-28-2009, 05:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •