9
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$
    – VaTTeRGeR
    Commented Apr 11, 2015 at 10:37

2 Answers 2

6
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Still no better solutions ? \$\endgroup\$
    – Winter
    Commented Jan 4, 2017 at 20:17
0
\$\begingroup\$

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


\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .