本文整理汇总了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();
}
}
}
}
示例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();
}
}
}
}