Text: setFont(Font f) : Text « org.eclipse.swt.widgets « Java by API






Text: setFont(Font f)


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class MainClass {

  public static void main(String[] a) {
    final Display d = new Display();
    final Shell s = new Shell(d);

    s.setSize(300, 300);

    s.setText("A ColorDialog 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 Color");
    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();

  }
}

           
       








Related examples in the same category

1.new Text(Composite parent, int style)
2.new Text(Shell shell, SWT.BORDER)
3.new Text(Shell s, SWT.MULTI | SWT.BORDER)
4.new Text(Shell shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL)
5.new Text(Shell shell, SWT.PASSWORD | SWT.BORDER)
6.new Text(Shell shell, SWT.READ_ONLY | SWT.BORDER)
7.new Text(Shell shell, SWT.RIGHT | SWT.BORDER)
8.new Text(Shell s, SWT.SINGLE)
9.new Text(Shell s, SWT.SINGLE| SWT.BORDER)
10.new Text(Shell s, SWT.WRAP | SWT.BORDER)
11.new Text(Shell s, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL)
12.Text: addFocusListener(FocusListener lis)
13.Text: addHelpListener(HelpListener lis)
14.Text: addKeyListener(KeyListener lis)
15.Text: addModifyListener(ModifyListener lis)
16.Text: addVerifyListener(VerifyListener lis)
17.Text: clearSelection()
18.Text: getSelectionCount()
19.Text: selectAll()
20.Text: setData(Object data)
21.Text: setEchoChar(char ch)
22.Text: setFocus()
23.Text: setLayoutData(Object layoutData)
24.Text: setText(String value)
25.Text: setTextLimit(int num)