0
我希望我可以創建一個我之前處理過的複合物。目標是顯示和隱藏循環複合以改變屏幕(滾動通過複合)。提前致謝。SWT創建一個被解僱的小部件(滾動通過複合)
public class prog {
static public void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell (display, SWT.CLOSE | SWT.TITLE | SWT.MIN);
shell.setText("EXAMPLE");
shell.setLayout(new GridLayout(1,false));
//I want comp1 initially be shown and then being hidden and that is shown comp2 with its components
final Composite comp1 = new Composite(shell, SWT.NONE);
comp1.setLayout(new GridLayout(1,false));
comp1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
final Composite comp2 = new Composite(shell, SWT.BORDER);
comp2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
GridData data = (GridData)comp2.getLayoutData(); // Assumes layout was set earlier
data.exclude = true; // Don't include control in the layout
comp2.setVisible(false);
comp2.layout(true);
Label t = new Label(comp2, SWT.NONE);
t.setText("must be shown");
Button btn_create = new Button(comp1, SWT.PUSH);
btn_create.setText("change composite");
btn_create.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true,1,1));
btn_create.addSelectionListener(new SelectionAdapter() { //evento quando il bottone viene premuto
public void widgetSelected(SelectionEvent e) {
GridData data3 = (GridData)comp1.getLayoutData(); // Assumes layout was set earlier
data3.exclude = true; // Don't include control in the layout
comp1.setVisible(false);
comp1.layout(true);
GridData data2 = (GridData)comp2.getLayoutData(); // Assumes layout was set earlier
data2.exclude = false; // Don't include control in the layout
comp2.setVisible(true);
comp2.layout(true);
System.out.println(comp2.getVisible());
}});
//swt_create.create(display, shell, create);
shell.setSize(500, 100);
shell.addControlListener(new ControlAdapter() { // fa in modo che la dimensione della finestra si sempre
public void controlResized(ControlEvent e) { // uguale
shell.setSize(500,400);
}
});
shell.open();
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) { // questo etodo serve a leggere gli eventi che compiamo durante
display.sleep(); // l'esecuzione, quando si clicca sulla x si passa avanti e il ciclo viene
} // chiuso
}
display.dispose();
}}
你可以這樣做。但隨後我在空間裏展示了什麼都沒有,我希望它只顯示我想要的東西。 – Araldar
根據您使用的佈局,您可以安排不會有任何空白空間。我爲GridLayout添加了一個示例。 –
對不起,如果我是一些noob .... – Araldar