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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class Sample {
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// Très important
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
// Le composite doit avoir un GridLayout avec deux colonnes
composite.setLayout(new GridLayout(2,false));
// A gauche on met la table
creationTable(composite);
// A droite, 3 composants de taille fixe
creationAutresWidgets(composite);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void creationAutresWidgets(Composite composite) {
final Image image = new Image(composite.getDisplay(), "C:/eclipse/workspace/test/src/logo.png");
final Canvas canvas = new Canvas(composite, SWT.NO_REDRAW_RESIZE);
GridData gridDataLogo = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
gridDataLogo.widthHint = 238;
gridDataLogo.heightHint = 99;
canvas.setLayoutData(gridDataLogo);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image, 0, 0);
}
});
Group groupAjoutBdc = new Group(composite, SWT.NONE);
GridData gridDataAjoutBdc = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
gridDataAjoutBdc.widthHint = 240;
groupAjoutBdc.setLayoutData(gridDataAjoutBdc);
groupAjoutBdc.setText("Ajouter un bon de commande");
final GridLayout gridLayoutGroupAjoutBdc = new GridLayout();
gridLayoutGroupAjoutBdc.numColumns = 4;
gridLayoutGroupAjoutBdc.horizontalSpacing = 0;
gridLayoutGroupAjoutBdc.makeColumnsEqualWidth = false;
gridLayoutGroupAjoutBdc.marginWidth = 0;
groupAjoutBdc.setLayout(gridLayoutGroupAjoutBdc);
Group groupRechercheBdc = new Group(composite, SWT.NONE);
GridData gridDataRechercheBdc = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
gridDataRechercheBdc.widthHint = 240;
groupRechercheBdc.setLayoutData(gridDataRechercheBdc);
groupRechercheBdc.setText("Rechercher un bon de commande");
final GridLayout gridLayoutGroupRechercheBdc = new GridLayout();
gridLayoutGroupRechercheBdc.numColumns = 2;
groupRechercheBdc.setLayout(gridLayoutGroupRechercheBdc);
}
private static void creationTable(Composite composite) {
final Table table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Colonne 1");
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Colonne 2");
TableColumn column3 = new TableColumn(table, SWT.NONE);
column3.setText("Colonne 3");
for (int i = 0; i < 11; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "Ligne n°" + i, "Coucou", "ca va ?" });
}
column1.pack();
column2.pack();
column3.pack();
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
table.setLayoutData(gd);
}
} |
Partager