Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: how to adjust the size on a graphic component

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to adjust the size on a graphic component

    So im trying to adjust the size on this graphic component code anyone have any ideas?

    public class DisplayComponent extends JComponent
    {
    	private boolean hasLetter = false;
    	private GameEngine game;
     
    		public void paintComponent(Graphics g)
    		{
    			// Recover Graphics2D
    			Graphics2D g2 = (Graphics2D) g;
     
    			Line2D.Double bottom = new Line2D.Double(100, 500, 600, 500);
    			g2.draw(bottom);
    			Line2D.Double side = new Line2D.Double(200, 500, 200, 100);
    			g2.draw(side);
    			Line2D.Double top = new Line2D.Double(200, 100, 450, 100);
    			g2.draw(top);
    			Line2D.Double hang = new Line2D.Double(450, 100, 450, 150);
    			g2.draw(hang);
                            //EVERYTHING BELOW IM TRYING TO ADJUST
    		        String newWord = game.getGuessWord();
    			g2.drawString(newWord, 350, 600);
     
    		}


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: how to adjust the size on a graphic component


  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to adjust the size on a graphic component

    The String newWord contains a string like(_ _ _ _) and what im trying to do is make whatever is in the variable newWorld display on the JFrame, to be bigger font.


  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,267
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: how to adjust the size on a graphic component

    See Graphics.setFont. If you wish to just change the current font, you can simply call getFont().deriveFont(fontizeasfloat) and pass that to setfont.

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to adjust the size on a graphic component

    ok here is my new code, yet it still doesnt seem to be changing

    		public void paintComponent(Graphics g)
    		{
    			// Recover Graphics2D
     
    			Graphics2D g2 = (Graphics2D) g;
     
    			Line2D.Double bottom = new Line2D.Double(100, 500, 600, 500);
    			g2.draw(bottom);
    			Line2D.Double side = new Line2D.Double(200, 500, 200, 100);
    			g2.draw(side);
    			Line2D.Double top = new Line2D.Double(200, 100, 450, 100);
    			g2.draw(top);
    			Line2D.Double hang = new Line2D.Double(450, 100, 450, 150);
    			g2.draw(hang);
                            //EVERYTHING BELOW IM TRYING TO ADJUST
    			String newWord = game.getGuessWord();
    			Font font = getFont().deriveFont(200);//<<<<<<<<<<<<NEW LINE
    			g2.setFont(font);//<<<<<<<<<<<<<<<<<<<<<<<<<NEW LINE
    			g2.drawString(newWord, 350, 600);
     
    		}

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,267
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: how to adjust the size on a graphic component

    Read the API for deriveFont, as I vaguely indicated in my post above to change the font size the parameter must be a float. (eg deriveFont(200f))

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to adjust the size on a graphic component

    Thanks that worked just like how i was wanting it, but why does it work when i just add an "f" at the end of that number. I mean i understood it had to be a float but my understanding was that floats and doubles are relatively the same in the way, only real difference is that float is like a point on a graph by itself. But just putting an "f" at the end? what does that mean? im relatively new to programming so forgive me if it sounds a little naive . Thanks for helping nevertheless

  8. #8
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: how to adjust the size on a graphic component

    Have you read the API for Font? What are the overloads of DeriveFont and what Type of parameters do they take?

    db

  9. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: how to adjust the size on a graphic component

    Also go through
    Lexical Structure

    db

Similar Threads

  1. Graphic angle
    By CoffeeBeans in forum Java Theory & Questions
    Replies: 1
    Last Post: August 22nd, 2010, 11:28 AM
  2. Graphic Environment Abstract Methods
    By striko_514 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 5th, 2010, 01:01 AM
  3. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM
  5. component
    By nasi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 4th, 2010, 07:40 PM