[SWT][Layout]problème de redimensionnement d'un Text
Bonjour,
j'ai un petit soucis pour redimensionner un widget Text avec SWT.
Mon problème se trouve ds une grille assez complexe mais j'ai fait un petit exemple qui reflète bien mon soucis : ne pas redimensionner le premier champ Text (le code se trouve plus bas).
Mode 2 colonnes fenetre "packée"
http://matthieu.brouillard.free.fr/pub/pack-2cols.jpg
Mode 2 colonnes fenetre extend
http://matthieu.brouillard.free.fr/pub/2cols.jpg
Mode 3 colonnes fenetre extend
http://matthieu.brouillard.free.fr/pub/3cols.jpg
Je met un petit bout de code pour illuster le problème (sans arguments mode 2 colonnes, avec mode 3 colonnes).
Je ne vois pas pourquoi ce design avec ce layout ne fonctionne pas, mais je suis loin d'être un spécialiste !
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class SWTTest {
Shell shell;
public static void main(String[] args) {
Display display = new Display();
SWTTest tester = new SWTTest ();
Shell shell = tester.open (display);
if (args.length==0) {
shell.setText (2 + " columns test");
tester.createWindow(shell, 2);
} else {
shell.setText (3 + " columns test");
tester.createWindow(shell, 3);
}
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
display.dispose ();
System.out.println("the end.");
}
private Shell open(Display display) {
shell = new Shell (display);
return shell;
}
private void createWindow(Composite parent, int nbCols) {
// On cree un GridLayout pr le nbre de colonnes
GridLayout gl = new GridLayout();
gl.numColumns = nbCols;
parent.setLayout(gl);
// Le text prend toutes les colonnes sauf la derniere
Text text1 = new Text(parent, SWT.BORDER);
text1.setText("text1");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = nbCols - 1;
text1.setLayoutData(gridData);
// Le bouton prend la derniere colonne
Button check = new Button(parent, SWT.CHECK);
check.setText("check");
// Le text prend toutes les colonnes
Text text2 = new Text(parent, SWT.BORDER);
text2.setText("text2");
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = nbCols;
text2.setLayoutData(gridData);
}
} |