本文整理汇总了Java中javax.swing.JEditorPane.requestFocus方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.requestFocus方法的具体用法?Java JEditorPane.requestFocus怎么用?Java JEditorPane.requestFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.requestFocus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performOpen
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void performOpen(JEditorPane[] panes) {
if (panes == null || panes.length == 0) {
StatusDisplayer.getDefault().setStatusText(Bundle.ERR_ShellConsoleClosed());
return;
}
JEditorPane p = panes[0];
Rng[] fragments = theHandle.getFragments();
int to = fragments[0].start;
p.requestFocus();
int pos = Math.min(p.getDocument().getLength() - 1, to);
p.setCaretPosition(pos);
try {
Rectangle r = p.modelToView(pos);
p.scrollRectToVisible(r);
} catch (BadLocationException ex) {
}
}
示例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();
}
}
}
}
示例3: 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();
}
}
}
}