styledtextexample.java

来自「用java 实现的IE browser适合于学者」· Java 代码 · 共 44 行

JAVA
44
字号
/*
 * Created on 2005-5-26
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.hnjchina.example.tableviewer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.LineBackgroundEvent;
import org.eclipse.swt.custom.LineBackgroundListener;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

/**
 * @author limeiyong
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StyledTextExample extends ViewPart {
    public void createPartControl(Composite parent) {
        
    }
    public void setFocus() {
    }
public	void	StyleText(final Composite parent){
    final StyledText styledText;
    parent.setLayout(new GridLayout());
    styledText = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    styledText.setLayoutData(new GridData(GridData.FILL_BOTH));
    styledText.addLineBackgroundListener(new LineBackgroundListener() {
      public void lineGetBackground(LineBackgroundEvent event) {
        if(styledText.getLineAtOffset(event.lineOffset) % 2 == 1)
          event.lineBackground = parent.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
      }
    });
    styledText.setText("Line 0\r\nLine 1\r\nLine 2\r\nLine 3\r\nLine 4\r\nLine 5\r\nLine 6");
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?