Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 96af96bcdc56599afb427da9d0df02db1121a667 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * StyledText example: use margins in StyledText
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 *
 * @since 3.5
 */
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet316 {
	public static void main(String[] args) {
		Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setText("Snippet 316");
		shell.setLayout(new FillLayout());
		StyledText text = new StyledText(shell, SWT.V_SCROLL | SWT.H_SCROLL);
		text.setText("StyledText with margins.");
		Font font = new Font(display, "Tahoma", 14, SWT.ITALIC);
		text.setText("\"If you go down to the woods today\nYou'd better not go alone\nIt's lovely down in the woods today\nBut safer to stay at home\"");
		StyleRange italic = new StyleRange();
		italic.font = font;
		text.setStyleRanges(new int[] {0, text.getCharCount()}, new StyleRange[] {italic});
		text.setMargins(30, 30, 30, 30);
		Color color = new Color (138, 226, 255);
		text.setMarginColor(color);
		shell.setSize(500, 300);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		font.dispose();
		display.dispose ();
	}
}

Back to the top