Results 1 to 3 of 3
  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default How to position stuff

    I have created a little canvas with a login form. Her is what it looks like:
    How to position stuff-canvas.png
    My question is: how should I position stuff correctly? Because I don't think I'm doing it efficiently.
    Here is what my render method looks like right now:
    Java Code:
    public void render(Screen screen) {
    		int fontSize = 15;
    		Font f = new Font("Verdana", Font.PLAIN, fontSize);
    		
    		int userTWidth = screen.getTextWidth("Username", f);
    		int passTWidth = screen.getTextWidth("Password", f);
    		int textPadding = 13;
    		int inputPadding = 5;
    		
    		Point userInputPos = new Point(200, 100);
    		Point passInputPos = new Point(200, 140);
    		
    		screen.renderText("Username: ", userInputPos.x - userTWidth - textPadding, userInputPos.y + fontSize+ 2, f, 0xFFFFFF);
    		screen.renderTile(userInputPos.x, userInputPos.y, input);
    		screen.renderText(username + (inputIndex == 0 ? marker : ""), userInputPos.x + inputPadding, userInputPos.y + fontSize+ 2, f, 0xFFFFFF);
    		
    		screen.renderText("Password: ", passInputPos.x - passTWidth - textPadding, passInputPos.y + fontSize+ 2, f, 0xFFFFFF);
    		screen.renderTile(passInputPos.x, passInputPos.y, input);
    		screen.renderText(password.replaceAll(".", "*") + (inputIndex == 1 ? marker : ""), passInputPos.x + inputPadding, passInputPos.y + fontSize+ 2, f, 0xFFFFFF);
    		
    	}
    The renderText basically renders text. And renderTile renders an image.

    (I have edited the code, and I can't change the canvas image because attachments don't work.)
    Last edited by PhQ; 12-23-2012 at 07:43 PM.

  2. #2
    Wizard0860 is offline Member
    Join Date
    Nov 2012
    Posts
    29
    Rep Power
    0

    Default Re: How to position stuff

    What do you need to position?

  3. #3
    Jeroen Mathon is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to position stuff

    HAve you tried using window manager.
    Or mayby using vectors

Similar Threads

  1. New to this stuff.. need help..
    By tkelley1620 in forum New To Java
    Replies: 3
    Last Post: 03-07-2012, 01:34 AM
  2. where the stuff goes?
    By Izabela in forum New To Java
    Replies: 16
    Last Post: 08-31-2010, 03:00 PM
  3. Replies: 6
    Last Post: 05-26-2010, 01:17 AM
  4. get position in string from caret position
    By helloworld111 in forum AWT / Swing
    Replies: 5
    Last Post: 02-19-2009, 02:36 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
  •