Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make scene2d.ui table with alternate row colours?

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?

like image 417
eby Avatar asked Jan 11 '23 09:01

eby


1 Answers

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();
like image 167
Sampo Pietikäinen Avatar answered Jan 18 '23 07:01

Sampo Pietikäinen