I created a dialog and added a button actor.
windowStyle = new Window.WindowStyle(boldFont, Color.WHITE, drawable);
dialog = new Dialog("Error", windowStyle);
dialog.getContentTable().add(resetButton);
but the problem is that when I do dialog.show(stage)
only the background of the dialog is at the center, and the string "Error" is at the top left corner of the dialog background while the resetButton is also not aligned.
You can do several things here. The
Dialog
class has at last three tables in it. The "Error" string is added to thetitleTable
. You could create an empty titled Dialog:dialog = new Dialog("", windowStyle);
and then add and center your title manually:
dialog.getTitleTable().add(new Label("Error", new Label.LabelStyle(boldFont, Color.WHITE)).center().expand();
Same for the
resetButton
, but you could use thegetContentTable()
orgetButtonTable()
methods.If you want to resize or reposition your dialog window, I found the only way to do so is to create your own Dialog class,
MyDialog extends Dialog
and override thegetPrefHeight()
,getPrefWidth()
andsetPosition(x, y)
methods.