FileDocCategorySizeDatePackage
FontDialogExample.javaAPI DocExample1730Sun Oct 31 09:41:06 GMT 2004None

FontDialogExample

public class FontDialogExample extends Object

Fields Summary
Display
d
Shell
s
Constructors Summary
FontDialogExample()

         d = new Display();
         s = new Shell(d);
        s.setSize(400,400);
        s.setImage(new Image(d, "c:\\icons\\JavaCup.ico"));
        s.setText("A FontDialog Example");
        s.setLayout(new FillLayout(SWT.VERTICAL));    
        final Text t = new Text(s, SWT.BORDER | SWT.MULTI);
        final Button b = new Button(s, SWT.PUSH | SWT.BORDER);
        b.setText("Change Font");
        b.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                FontDialog fd = new FontDialog(s, SWT.NONE);
                fd.setText("Select Font");
                fd.setRGB(new RGB(0,0,255));
                FontData defaultFont = new FontData("Courier",10,SWT.BOLD);
                fd.setFontData(defaultFont);     
                FontData newFont = fd.open();
                if(newFont==null)
                    return;
                t.setFont(new Font(d, newFont));
                t.setForeground(new Color(d, fd.getRGB()));
            }
        });
        s.open();
        
        while(!s.isDisposed()){
            if(!d.readAndDispatch())
                d.sleep();
        }
        d.dispose();
    
Methods Summary