可視性プロパティに従って、コンポジット内のボタンを再描画したいと思います。合成して、そこにあるボタンに従ってサイズを変更し、次のコードを使用して合成を更新しています。 問題:以下のコードは正常に機能しますが、ボタンがコンポジットで再配置されることはありません 。助けてください。再配置するコードに欠けているものはありますか?
public void redraw_buttons() {
int offsetButton = 5;
int buttonHeight =28*3;
for (Control kid : compositeButtons.getChildren()) {
if (kid.getClass() == Button.class) {
if(kid.getVisible() == true){
kid.setLocation(0, 0);//layout(true, true);
kid.setSize(50,60);
kid.redraw();
kid.pack();
compositeButtons.redraw();
kid.setRedraw(true);
kid.setBounds(10, offsetButton, 259, buttonHeight);
kid.redraw();
offsetButton = offsetButton + buttonHeight;
}}
}
compositeButtons.redraw();
}
また、コンポジットでボタンを作成するために、次のコードを使用しています
//コンポジットの初期化---
compositeButtons = new Composite(shell, SWT.BORDER);
compositeButtons.setLayout(null);
FormData fd_compositeButtons = new FormData();
fd_compositeButtons.top = new FormAttachment(lblUserLoggedinOnServer, 6);
fd_compositeButtons.bottom = new FormAttachment(textRecentLog, -6);
fd_compositeButtons.right = new FormAttachment(textRecentLog, 0, SWT.RIGHT);
fd_compositeButtons.left = new FormAttachment(0, 30);
compositeButtons.setLayoutData(fd_compositeButtons);
compositeButtons.layout(true, true);
getShell().layout(true, true);
//コンポジットにボタンを追加-
int offsetButton = 5;
int buttonHeight =28*3;
MakeAppointmentRequestButton = new Button(compositeButtons, SWT.NONE);
MakeAppointmentRequestButton.setBounds(10, offsetButton, 259, buttonHeight);
//MakeAppointmentRequestButton.layout(true, true);
MakeAppointmentRequestButton.setRedraw(true);
MakeAppointmentRequestButton.setText("Make Appointment");
offsetButton = offsetButton + buttonHeight;
GotoAppointmentRequestButton = new Button(compositeButtons, SWT.NONE);
GotoAppointmentRequestButton.setBounds(10, offsetButton, 259, buttonHeight);//(10, offsetButton, 259, 28*3);
GotoAppointmentRequestButton.setRedraw(true);
GotoAppointmentRequestButton.setText("Goto Appointment");
offsetButton = offsetButton + buttonHeight;
CancelAppointmentRequestButton= new Button(compositeButtons, SWT.NONE);
CancelAppointmentRequestButton.setBounds(10, offsetButton, 259, buttonHeight);//(10, 28*3+5, 259, 28*3);
CancelAppointmentRequestButton.setRedraw(true);
CancelAppointmentRequestButton.setText("Cancel Appointment");
offsetButton = offsetButton + buttonHeight;
さまざまなリンクがpack()、redraw()プロパティも試しているのを見てきました。ただし、問題:カスタム関数redraw_buttons()を呼び出しても、ボタンがコンポジットで再配置されることはありません。
助けてください。再配置するコードに欠けているものはありますか?これを行う方法を提案してください。私はSWTを初めて使用します。
ありがとう..
******* 編集新規更新 ********
エラーの原因は
1.)redraw_buttons()
メインスレッドで関数が呼び出されませんでした。
_appLoader.display.getDefault().asyncExec(new Runnable() {
public void run() {
_appLoader.MyObj.redraw_buttons();
}
});
// This gave access to main thread.
2.)複合フレームはredraw_buttons()でサイズ変更されませんでした。
// Code: On Which I am still working upon.
シェルのサイズを変更する必要がありますか?plsは提案します。
ご協力いただきありがとうございます。