当前位置: 首页>>代码示例>>Java>>正文


Java JEditorPane.select方法代码示例

本文整理汇总了Java中javax.swing.JEditorPane.select方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.select方法的具体用法?Java JEditorPane.select怎么用?Java JEditorPane.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JEditorPane的用法示例。


在下文中一共展示了JEditorPane.select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * 
 */
public void actionPerformed(ActionEvent e)
{
	if (e.getSource() instanceof mxGraphComponent)
	{
		mxGraphComponent graphComponent = (mxGraphComponent) e
				.getSource();
		Component editorComponent = null;

		if (graphComponent.getCellEditor() instanceof mxCellEditor)
		{
			editorComponent = ((mxCellEditor) graphComponent
					.getCellEditor()).getEditor();
		}

		if (editorComponent instanceof JEditorPane)
		{
			JEditorPane editorPane = (JEditorPane) editorComponent;
			int start = editorPane.getSelectionStart();
			int ende = editorPane.getSelectionEnd();
			String text = editorPane.getSelectedText();

			if (text == null)
			{
				text = "";
			}

			try
			{
				HTMLEditorKit editorKit = new HTMLEditorKit();
				HTMLDocument document = (HTMLDocument) editorPane
						.getDocument();
				document.remove(start, (ende - start));
				editorKit.insertHTML(document, start, ((bold) ? "<b>"
						: "<i>") + text + ((bold) ? "</b>" : "</i>"),
						0, 0, (bold) ? HTML.Tag.B : HTML.Tag.I);
			}
			catch (Exception ex)
			{
				ex.printStackTrace();
			}

			editorPane.requestFocus();
			editorPane.select(start, ende);
		}
		else
		{
			mxIGraphModel model = graphComponent.getGraph().getModel();
			model.beginUpdate();
			try
			{
				graphComponent.stopEditing(false);
				graphComponent.getGraph().toggleCellStyleFlags(
						mxConstants.STYLE_FONTSTYLE,
						(bold) ? mxConstants.FONT_BOLD
								: mxConstants.FONT_ITALIC);
			}
			finally
			{
				model.endUpdate();
			}
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:67,代码来源:EditorActions.java

示例2: actionPerformed

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * 
 */
public void actionPerformed(ActionEvent e) {
  if (e.getSource() instanceof mxGraphComponent) {
    mxGraphComponent graphComponent = (mxGraphComponent) e.getSource();
    Component editorComponent = null;

    if (graphComponent.getCellEditor() instanceof mxCellEditor) {
      editorComponent = ((mxCellEditor) graphComponent.getCellEditor()).getEditor();
    }

    if (editorComponent instanceof JEditorPane) {
      JEditorPane editorPane = (JEditorPane) editorComponent;
      int start = editorPane.getSelectionStart();
      int ende = editorPane.getSelectionEnd();
      String text = editorPane.getSelectedText();

      if (text == null) {
        text = "";
      }

      try {
        HTMLEditorKit editorKit = new HTMLEditorKit();
        HTMLDocument document = (HTMLDocument) editorPane.getDocument();
        document.remove(start, (ende - start));
        editorKit.insertHTML(document, start,
            ((bold) ? "<b>" : "<i>") + text + ((bold) ? "</b>" : "</i>"), 0, 0,
            (bold) ? HTML.Tag.B : HTML.Tag.I);
      } catch (Exception ex) {
        ex.printStackTrace();
      }

      editorPane.requestFocus();
      editorPane.select(start, ende);
    } else {
      mxIGraphModel model = graphComponent.getGraph().getModel();
      model.beginUpdate();
      try {
        graphComponent.stopEditing(false);
        graphComponent.getGraph().toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE,
            (bold) ? mxConstants.FONT_BOLD : mxConstants.FONT_ITALIC);
      } finally {
        model.endUpdate();
      }
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:49,代码来源:EditorActions.java


注:本文中的javax.swing.JEditorPane.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。