9

I'm new to libgdx and I'm currently working on TableLayout and wondering how could I draw borders for each cells.

I've done some research on this but it seems that I could come up with this solution only: https://stackoverflow.com/questions/13828423/drawing-table-borders-in-libgdx-0-9-7

However, turning on the debug option would be a bit dumb and it's not what I want. I'd like to control the color, thickness of the cell border. Is there anyway to achieve this?

Thanks!

user15783
  • 347
  • 1
  • 3
  • 8
  • There's also someone suggesting to use a ninepatch as background for the table. You could try to get the tables size and but a ninepatch behind/in front of it with a transparent middlepart and visible outer part – VaTTeRGeR Apr 11 '15 at 10:37

2 Answers2

6

I don't believe there is a built-in function for this.

You have a few options though:

  1. Use a 9-patch for table background with a border (thats what I do)

  2. Place another table underneath the main table, and make the size a bit bigger so you can see the edges, giving the impression of a border. This is probably your best choice since you want to control color/thickness etc.

Green_qaue
  • 1,893
  • 4
  • 24
  • 55
0

Another option besides the ones mentioned is to use Pixmap to draw the rectangle border and then use it as the background. It will give the idea of a border. The code below uses KTX so LibGDX with Kotlin.

    val pixmap = Pixmap(64, 64, Pixmap.Format.RGBA8888)        
    pixmap.setColor(Color.BLACK)
    pixmap.drawRectangle(0,0,64,64)
    val borderTexture = TextureRegionDrawable(Texture(pixmap))
    pixmap.dispose()

// initialize table etc... table.background = borderTexture