Trong trường hợp của tôi, tôi có hai con của SashForm
, nhưng câu hỏi áp dụng cho tất cả Composite
s.Thay đổi thứ tự của trẻ em của một SWT Composite
class MainWindow {
Sashform sashform;
Tree child1 = null;
Table child2 = null;
MainWindow(Shell shell) {
sashform = new SashForm(shell, SWT.NONE);
}
// Not called from constructor because it needs data not available at that time
void CreateFirstChild() {
...
Tree child1 = new Tree(sashform, SWT.NONE);
}
void CreateSecondChild() {
...
Table child2 = new Table(sashform, SWT.NONE);
}
}
Tôi không biết trước thứ tự các phương thức này sẽ được gọi. Làm cách nào để đảm bảo rằng child1
được đặt ở bên trái và child2
ở bên phải? Ngoài ra, có cách nào để thay đổi thứ tự của chúng là con của sashform
sau chúng được tạo không?
Hiện nay ý tưởng tốt nhất của tôi là để đưa vào giữ chỗ như thế này:
class MainWindow {
Sashform sashform;
private Composite placeholder1;
private Composite placeholder2;
Tree child1 = null;
Table child2 = null;
MainWindow(Shell shell) {
sashform = new SashForm(shell, SWT.NONE);
placeholder1 = new Composite(sashform, SWT.NONE);
placeholder2 = new Composite(sashform, SWT.NONE);
}
void CreateFirstChild() {
...
Tree child1 = new Tree(placeholder1, SWT.NONE);
}
void CreateSecondChild() {
...
Table child2 = new Table(placeholder2, SWT.NONE);
}
}
. Tôi chỉ bỏ lỡ sự tồn tại của 'moveAbove' vì tôi đang tìm kiếm trong số các phương thức' Composite'. –
Cảm ơn thông tin này :) Một điều tốt cần lưu ý là bạn có thể sử dụng null để di chuyển nó lên đầu. –