title: Center Justify Text in libgdx
body: <p>I have just started with LibGdx and I have figured out how to center text with it. Now I am having trouble with center justifying text. I was wondering if someone can help. I have attach my code for centering. Thank you in advance.</p>
  
  <pre><code>package com.tutorials.game;
  
  import com.badlogic.gdx.ApplicationAdapter;
  import com.badlogic.gdx.Gdx;
  import com.badlogic.gdx.graphics.GL20;
  import com.badlogic.gdx.graphics.Texture;
  import com.badlogic.gdx.graphics.g2d.BitmapFont;
  import com.badlogic.gdx.graphics.g2d.GlyphLayout;
  import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  
  public class TextDemo extends ApplicationAdapter {
      SpriteBatch batch;
      BitmapFont font;
      String myText;
      GlyphLayout layout = new GlyphLayout();
  
      @Override
      public void create () {
          batch = new SpriteBatch();
          font = new BitmapFont(Gdx.files.internal("myFont.fnt"));
          myText = "I took one, one cause you left me\n"
                 + "Two, two for my family\n"
                 + "Three, three for my heartache";
          layout.setText(font,myText);
      }
  
      @Override
      public void render () {
          Gdx.gl.glClearColor(0, 0, 0, 1);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
          float x = Gdx.graphics.getWidth()/2 - layout.width/2;
          float y = Gdx.graphics.getHeight()/2 + layout.height/2;
  
          batch.begin();
          font.draw(batch,layout,x,y);//Center Text
          batch.end();
  }
  </code></pre>