Results 1 to 6 of 6
  1. #1
    ravi.joshi53 is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Thumbs up How to enable smooth rendering of objects(ex. line, circle) in applet

    Hi, is there any option in Applet by which we can enable smooth rendering of simple
    objects. I am drawing lines in screen, which are not so much smooth.
    Have a look at attached snapshot.
    Thank you.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How to enable smooth rendering of objects(ex. line, circle) in applet

    Set the antialias rendering hint on the Graphics2D object:
    Java Code:
    public void paintComponent(Graphics g){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);
    Last edited by doWhile; 10-14-2011 at 09:12 PM. Reason: Fixed code

  3. #3
    ravi.joshi53 is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default Re: How to enable smooth rendering of objects(ex. line, circle) in applet

    Quote Originally Posted by doWhile View Post
    Set the antialias rendering hint on the Graphics2D object:
    Java Code:
    public void paintComponent(Graphics g){
        Graphics g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);
    Hey, I am getting a compilation error.

    Cannot find symbol
    Symbol: method setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)

    I am working in applet. I have public void paint(Graphics screen){} instead of paintComponent(Graphics g). Is this the reason of the error? what to do now?

  4. #4
    anura is offline Member
    Join Date
    Oct 2011
    Location
    Kraków Poland
    Posts
    3
    Rep Power
    0

    Default Re: How to enable smooth rendering of objects(ex. line, circle) in applet

    Java Code:
    Graphics2D g2d = (Graphics2D) g;
    http://home.cogeco.ca/~ve3ll/jatutorg.htm Tutorial 16 - Graphics and Imaging
    Last edited by anura; 10-14-2011 at 07:54 PM.

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How to enable smooth rendering of objects(ex. line, circle) in applet

    My telepathy skills lack practice, so I can't see your code to comment on why you are receiving the error (in other words, please post the appropriate code). Quick note however, I did edit my code above as the cast was supposed to be to a Graphics2D object (my bad)...which - my rusty telepathy skills tells me - might be the problem.
    Last edited by doWhile; 10-14-2011 at 09:13 PM.

  6. #6
    anura is offline Member
    Join Date
    Oct 2011
    Location
    Kraków Poland
    Posts
    3
    Rep Power
    0

    Default Re: How to enable smooth rendering of objects(ex. line, circle) in applet

    Graphics2D g2d

Similar Threads

  1. draw smooth dash-ed line
    By sarveshwar in forum Java 2D
    Replies: 3
    Last Post: 03-01-2011, 07:23 AM
  2. Xml Rendering BASE64 break line problem
    By justinazz in forum XML
    Replies: 0
    Last Post: 01-05-2011, 04:46 PM
  3. Replies: 9
    Last Post: 06-26-2010, 03:16 PM
  4. Replies: 7
    Last Post: 04-18-2010, 07:09 AM
  5. Circle and line
    By c_walker in forum New To Java
    Replies: 1
    Last Post: 01-27-2010, 03:56 AM

Posting Permissions

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