I have created a scene2d.ui Table
and would like to alternate the background colours of each row.
I've had a look through the various table and cell methods but there doesn't seem to be an obvious way of doing it.
Is it even possible? And if so, what's the easiest way of going about it?
I’ve used drawable backgrounds with one colored pixel. I haven’t found easier way even though it is far from elegant.
//Pixmap with one pixel
Pixmap pm1 = new Pixmap(1, 1, Format.RGB565);
pm1.setColor(Color.GREEN);
pm1.fill();
Pixmap pm2 = new Pixmap(1, 1, Format.RGB565);
pm2.setColor(Color.RED);
pm2.fill();
dialogueWindow = getWindow();
dialogueWindow.setTitle("New Game");
// The table that will have the green color
Table row1 = new Table(mySkin);
row1.add(nameStation);
row1.add(nameStationField);
row1.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pm1))));
dialogueWindow.add(row1);
dialogueWindow.row();
// The table that will have the green color
Table row2 = new Table(mySkin);
row2.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pm2))));
row2.add(cancel).size(120, 60);
row2.add(ok).size(100, 60);
dialogueWindow.add(row2).fillX();
dialogueWindow.row();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With