Example usage for org.eclipse.swt.widgets Label setFont

List of usage examples for org.eclipse.swt.widgets Label setFont

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label setFont.

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.

Usage

From source file:FontDialogColorFontData.java

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Font Chooser");
    shell.setLayout(new GridLayout(2, false));
    final Label fontLabel = new Label(shell, SWT.NONE);
    fontLabel.setText("The selected font");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Font...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Font font = null;//w  w  w.j av a  2s . co m
            Color color = null;

            FontDialog dlg = new FontDialog(shell);

            if (font != null)
                dlg.setFontList(fontLabel.getFont().getFontData());
            if (color != null)
                dlg.setRGB(color.getRGB());

            if (dlg.open() != null) {
                if (font != null)
                    font.dispose();
                if (color != null)
                    color.dispose();

                font = new Font(shell.getDisplay(), dlg.getFontList());
                fontLabel.setFont(font);

                color = new Color(shell.getDisplay(), dlg.getRGB());
                fontLabel.setForeground(color);

                shell.pack();

                if (font != null)
                    font.dispose();
                if (color != null)
                    color.dispose();
            }
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    // Create the main window
    final Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(2, false));

    final Label fontLabel = new Label(shell, SWT.NONE);
    fontLabel.setText("The selected font");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Font...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(shell);
            Font font = null;/*from  ww w  .j a  va2  s .  com*/
            Color color = null;

            if (font != null)
                dlg.setFontList(fontLabel.getFont().getFontData());
            if (color != null)
                dlg.setRGB(color.getRGB());

            if (dlg.open() != null) {
                if (font != null)
                    font.dispose();
                if (color != null)
                    color.dispose();

                font = new Font(shell.getDisplay(), dlg.getFontList());
                fontLabel.setFont(font);

                color = new Color(shell.getDisplay(), dlg.getRGB());
                fontLabel.setForeground(color);

                shell.pack();
            }
        }
    });

    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:grafici.PazientiTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart.  This example uses monthly data.
 *
 * @param title  the frame title./*  ww w. j  a  va 2  s  .  c om*/
 */
public PazientiTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);

    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));
    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}

From source file:grafici.FattureTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * /*from  www  . ja  v  a2 s. c o  m*/
 * @param title
 *            the frame title.
 */
public FattureTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);
    System.out.println(2);
    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));
    JPanel chartPanel = createPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}

From source file:grafici.MediciTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * /*from   w  ww.j  a  va2 s.c o m*/
 * @param title
 *            the frame title.
 */
public MediciTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);

    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));
    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}

From source file:grafici.PrenotazioneTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * /*from   w  w w.ja v  a 2 s . com*/
 * @param title
 *            the frame title.
 */
public PrenotazioneTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);

    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));
    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}

From source file:org.jcryptool.visual.verifiablesecretsharing.views.ReconstructionChartComposite.java

/**
 * Generates the head of the tab. The head has a title and a description.
 *///from  w  w  w  .j  av a 2s  .  com
private void createHead() {
    final Composite head = new Composite(this, SWT.NONE);
    head.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    head.setLayout(new GridLayout());

    final Label label = new Label(head, SWT.NONE);
    label.setFont(FontService.getHeaderFont());
    label.setText(Messages.VerifiableSecretSharingComposite_tab_title);
    stDescription = new StyledText(head, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
    stDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    if (reconstructedPolynom.toString().compareTo("0") == 0) {
        stDescription.setText(Messages.ChartComposite_noGraph);
    } else {
        stDescription.setText(reconstructedPolynom.toString());
    }
}

From source file:WordJumbles.java

public WordJumbles(String word) {
    this.word = word;

    shell.setText("Word Jumbles");

    labelsRowOne = new Label[word.length()];
    labelsRowTwo = new Label[word.length()];

    int width = 40;

    // In the production version, you need to implement random permutation
    // generation.
    // Apache Jakarta Commons provides this function, see
    // org.apache.commons.math.random.RandomDataImpl
    int[] randomPermutation = { 5, 2, 6, 3, 1, 4, 0 };

    for (int i = 0; i < word.length(); i++) {
        final Label labelRowOne = new Label(shell, SWT.BORDER);
        labelsRowOne[i] = labelRowOne;//  w  w w . j  a  va 2s .  co m
        labelRowOne.setBounds(10 + width * i, 10, width - 5, width - 5);
        labelRowOne.setFont(font);
        labelRowOne.setText(word.charAt(randomPermutation[i]) + "");
        labelRowOne.setAlignment(SWT.CENTER);

        setDragSource(labelRowOne);
        //setDropTarget(labelRowOne);

        final Label labelRowTwo = new Label(shell, SWT.BORDER);
        labelsRowTwo[i] = labelRowTwo;
        labelRowTwo.setBounds(10 + width * i, 20 + width, width - 5, width - 5);
        labelRowTwo.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        labelRowTwo.setFont(font);
        labelRowTwo.setAlignment(SWT.CENTER);

        setDragSource(labelRowTwo);
        //setDropTarget(labelRowTwo);
    }

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:org.eclipse.swt.examples.ole.win32.OleBrowserView.java

/**
 * Creates the Web browser toolbar./*from w  w w.ja v a  2 s  .c  o  m*/
 */
private void createToolbar() {
    // Add a toolbar
    ToolBar bar = new ToolBar(displayArea, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    bar.setLayoutData(gridData);

    // Add a button to navigate backwards through previously visited web sites
    webCommandBackward = new ToolItem(bar, SWT.NONE);
    webCommandBackward.setToolTipText(OlePlugin.getResourceString("browser.Back.tooltip"));
    webCommandBackward.setText(OlePlugin.getResourceString("browser.Back.text"));
    webCommandBackward.setImage(OlePlugin.images[OlePlugin.biBack]);
    webCommandBackward.setEnabled(false);
    webCommandBackward.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.GoBack();
    });

    // Add a button to navigate forward through previously visited web sites
    webCommandForward = new ToolItem(bar, SWT.NONE);
    webCommandForward.setToolTipText(OlePlugin.getResourceString("browser.Forward.tooltip"));
    webCommandForward.setText(OlePlugin.getResourceString("browser.Forward.text"));
    webCommandForward.setImage(OlePlugin.images[OlePlugin.biForward]);
    webCommandForward.setEnabled(false);
    webCommandForward.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.GoForward();
    });

    // Add a separator
    new ToolItem(bar, SWT.SEPARATOR);

    // Add a button to navigate to the Home page
    webCommandHome = new ToolItem(bar, SWT.NONE);
    webCommandHome.setToolTipText(OlePlugin.getResourceString("browser.Home.tooltip"));
    webCommandHome.setText(OlePlugin.getResourceString("browser.Home.text"));
    webCommandHome.setImage(OlePlugin.images[OlePlugin.biHome]);
    webCommandHome.setEnabled(false);
    webCommandHome.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.GoHome();
    });

    // Add a button to abort web page loading
    webCommandStop = new ToolItem(bar, SWT.NONE);
    webCommandStop.setToolTipText(OlePlugin.getResourceString("browser.Stop.tooltip"));
    webCommandStop.setText(OlePlugin.getResourceString("browser.Stop.text"));
    webCommandStop.setImage(OlePlugin.images[OlePlugin.biStop]);
    webCommandStop.setEnabled(false);
    webCommandStop.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.Stop();
    });

    // Add a button to refresh the current web page
    webCommandRefresh = new ToolItem(bar, SWT.NONE);
    webCommandRefresh.setToolTipText(OlePlugin.getResourceString("browser.Refresh.tooltip"));
    webCommandRefresh.setText(OlePlugin.getResourceString("browser.Refresh.text"));
    webCommandRefresh.setImage(OlePlugin.images[OlePlugin.biRefresh]);
    webCommandRefresh.setEnabled(false);
    webCommandRefresh.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.Refresh();
    });

    // Add a separator
    new ToolItem(bar, SWT.SEPARATOR);

    // Add a button to search the web
    webCommandSearch = new ToolItem(bar, SWT.NONE);
    webCommandSearch.setToolTipText(OlePlugin.getResourceString("browser.Search.tooltip"));
    webCommandSearch.setText(OlePlugin.getResourceString("browser.Search.text"));
    webCommandSearch.setImage(OlePlugin.images[OlePlugin.biSearch]);
    webCommandSearch.setEnabled(false);
    webCommandSearch.addListener(SWT.Selection, e -> {
        if (webBrowser == null)
            return;
        webBrowser.GoSearch();
    });

    // Add a text area for Users to enter a url
    Composite addressBar = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    addressBar.setLayoutData(gridData);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    addressBar.setLayout(gridLayout);

    Label addressLabel = new Label(addressBar, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    addressLabel.setLayoutData(gridData);
    addressLabel.setText(OlePlugin.getResourceString("browser.Address.label"));
    addressLabel.setFont(OlePlugin.browserFont);

    webUrl = new Text(addressBar, SWT.SINGLE | SWT.BORDER);
    webUrl.setFont(OlePlugin.browserFont);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    webUrl.setLayoutData(gridData);
    webUrl.addFocusListener(FocusListener
            .focusGainedAdapter(e -> webNavigateButton.getShell().setDefaultButton(webNavigateButton)));

    // Add a button to navigate to the web site specified in the Text area defined above
    webNavigateButton = new Button(addressBar, SWT.PUSH);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    webNavigateButton.setLayoutData(gridData);
    webNavigateButton.setText(OlePlugin.getResourceString("browser.Go.text"));
    webNavigateButton.setFont(OlePlugin.browserFont);
    webNavigateButton.addListener(SWT.Selection, event -> {
        if (webBrowser == null)
            return;
        webBrowser.Navigate(webUrl.getText());
    });
}

From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java

/**
 * Tell the user that the transformation is not running or that there is no monitoring configured.
 *///w  w w  .j  a  v a2  s  .co  m
private void showEmptyGraph() {
    if (perfComposite.isDisposed()) {
        return;
    }

    emptyGraph = true;

    Label label = new Label(perfComposite, SWT.CENTER);
    label.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoringNotEnabled.Message"));
    label.setBackground(perfComposite.getBackground());
    label.setFont(GUIResource.getInstance().getFontMedium());

    FormData fdLabel = new FormData();
    fdLabel.left = new FormAttachment(5, 0);
    fdLabel.right = new FormAttachment(95, 0);
    fdLabel.top = new FormAttachment(5, 0);
    label.setLayoutData(fdLabel);

    Button button = new Button(perfComposite, SWT.CENTER);
    button.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoring.Button"));
    button.setBackground(perfComposite.getBackground());
    button.setFont(GUIResource.getInstance().getFontMedium());

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            TransGraph.editProperties(spoon.getActiveTransformation(), spoon, spoon.rep, true,
                    TransDialog.Tabs.MONITOR_TAB);
        }
    });

    FormData fdButton = new FormData();
    fdButton.left = new FormAttachment(40, 0);
    fdButton.right = new FormAttachment(60, 0);
    fdButton.top = new FormAttachment(label, 5);
    button.setLayoutData(fdButton);

    perfComposite.layout(true, true);
}