TextLayoutUnicode.java Source code

Java tutorial

Introduction

Here is the source code for TextLayoutUnicode.java

Source

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
//package org.eclipse.swt.snippets;
/*
 * TextLayout example snippet: draw internationalized styled text on a shell
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class TextLayoutUnicode {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);

        Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD);

        Color blue = display.getSystemColor(SWT.COLOR_BLUE);
        Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);

        final TextLayout layout = new TextLayout(display);
        TextStyle style1 = new TextStyle(font1, yellow, blue);

        layout.setText("English \u65E5\u672C\u8A9E  \u0627\u0644\u0639\u0631\u0628\u064A\u0651\u0629");
        layout.setStyle(style1, 8, 21);

        shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        shell.addListener(SWT.Paint, new Listener() {
            public void handleEvent(Event event) {
                layout.draw(event.gc, 10, 10);
            }
        });
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        font1.dispose();
        layout.dispose();
        display.dispose();
    }
}