问题描述
我正在尝试调整 scene2d.ui 窗口(基本上是一个可以移动的表格)及其内容的大小.到目前为止,我只能成功更改窗口大小本身,但不能更改其内容.我这样做是这样的:
I'm attempting to resize a scene2d.ui window (which is basically a table that can be moved around) and its contents. So far I can only successfully change the window size itself, but not its contents. I'm doing it like this:
window.setWidth(newTableWidth);
textField.setWidth(newFieldWidth);
window.invalidate(); <--- New size of window is drawn properly when invalidate() is called
textField.invalidate(); <--- New textField size is NOT drawn, however
在这种情况下,窗口包含一个文本字段,我试图与窗口一起调整它的大小,但只有窗口会以其新大小重绘,而文本字段保持不变.
In this case, the window contains a text field which I'm trying to resize along with the window, but only the window gets redrawn with its new size while the text field remains the same.
如何正确更新窗口中的小部件?
How do I properly update the widgets within the window?
推荐答案
根据BeenX 的回答,很明显,大小是在包含小部件的表格的单元格上设置的,而不是在小部件本身上设置的.table.add()
方法返回一个单元格,因此在运行 table.add(textField).width(600).height(60)
时,宽度和高度是应用于此单元格.
Based on BeenX's answer, it's evident that the size is set on the cell of the table that contains the widget, rather than on the widget itself. The table.add()
method returns a cell, so when running table.add(textField).width(600).height(60)
the width and height is being applied to this cell.
因此,我更新现有单元格的解决方案是使用 table.getCells()
找到我要更新的单元格,然后对其应用新宽度.下面的示例更改列表中最后一个单元格的宽度.
Hence my solution to update an already existing cell was to find the cell I want to update with table.getCells()
then apply the new width on that. The example below changes the width of the last cell in the list.
List<Cell> cells = window.getCells();
Cell cell = cells.get(cells.size()-1);
cell.width(newWidth);
这篇关于如何更改窗口/表格中现有 scene2d.ui 小部件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!