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
|
myLayout = new RowLayout(SWT.VERTICAL);
myLayout.wrap = true;
parent.setLayout(myLayout);
label = new Label(parent, SWT.NONE);
label.setText("Je suis un label");
final Button bouton = new Button(parent, SWT.PUSH);
bouton.setText("Je suis le bouton");
bouton.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
FontDialog ftd = new FontDialog(parent.getShell());
ftd.setText("choisir une police");
ftd.setFontList(label.getFont().getFontData());
ftd.setRGB(label.getForeground().getRGB());
ftd.open();
//On récupère la couleur et on créé l'objet pour l'attribuer au label
RGB colorRGB = ftd.getRGB();
final Color colorText = new Color(parent.getShell().getDisplay(), colorRGB);
label.setForeground(colorText);
//On récupère la font
FontData [] fdata = ftd.getFontList();
final Font fontText = new Font(parent.getShell().getDisplay(), fdata);
label.setFont(fontText);
// Nettoyage
bouton.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
colorText.dispose();
fontText.dispose();
}
}));
}
}); |
Partager