Results 1 to 3 of 3
  1. #1
    Crazy Caveman is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default Graphics2D setRenderingHint not working

    Hello I am trying to make text show in my JFrame. I keep on getting this error:
    "Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Antialiased rendering mode is not compatible with Text-specific antialiasing enable key"

    I have no idea how to if it all I know is that it has something to do with the setRenderingHint function.

    Main Class:
    Java Code:
    import java.awt.*;
    import javax.swing.JFrame;
    
    public class Main extends JFrame{
    
    	public static void main(String[] args)
    	{
    		DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);
    		Main m = new Main();
    		m.run(dm);
    	}
    	
    	public void run(DisplayMode dm){
    		setBackground(Color.PINK);
    		setForeground(Color.WHITE);
    		setFont(new Font("Arila", Font.PLAIN, 24));
    		
    		Screen s = new Screen();
    		try{
    			s.setFullScreen(dm, this);
    			try{
    				Thread.sleep(5000);
    			}catch(Exception e){
    				
    			}
    		}finally{
    			s.restoreScreen();
    		}
    		
    	}
    	
    	public void paint(Graphics g){
    		if(g instanceof Graphics2D){
    			Graphics2D g2 = (Graphics2D)g;
    			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    		}
    		
    		g.drawString("Hello World", 200, 200);
    		
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You've got the wrong value for the key you're using. Look in the API and you'll find the correct value -- it's easy once you see it.

    RenderingHints API

    But more importantly you're doing your graphics wrong as you shouldn't be drawing directly in a JFrame, and doing this will bring you nothing but grief. Draw instead in a JPanel's paintComponent method and add this JPanel to your JFrame, probably BorderLayout.CENTER.
    Last edited by Fubarable; 08-27-2010 at 12:18 PM.

  3. #3
    Crazy Caveman is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. working with JC
    By yuhobebbho in forum New To Java
    Replies: 0
    Last Post: 02-10-2010, 11:22 PM
  2. Replies: 3
    Last Post: 02-13-2009, 07:59 AM
  3. Graphics2D: stack overflow error
    By rosh72851 in forum New To Java
    Replies: 11
    Last Post: 10-15-2008, 09:01 PM
  4. Replies: 8
    Last Post: 05-28-2008, 07:00 AM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 08:16 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
  •