本文整理匯總了Java中javax.swing.text.StyledEditorKit.getInputAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java StyledEditorKit.getInputAttributes方法的具體用法?Java StyledEditorKit.getInputAttributes怎麽用?Java StyledEditorKit.getInputAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.StyledEditorKit
的用法示例。
在下文中一共展示了StyledEditorKit.getInputAttributes方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
// FIX bold word if no selection! (only if chars on both sides are letters or digits)
// nn|nn -> BB|BB
// nn|. -> nn|.
// <sp>|<sp> -> <sp>|<sp>
// BBB|nnn -> nnn|nnn
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
if(k != null)
{
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isBold(as);
SimpleAttributeSet newAttrs = new SimpleAttributeSet();
StyleConstants.setBold(newAttrs, !on);
setCharacterAttributes(ed, newAttrs, false);
}
}
}
示例2: actionPerformed
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e){
JEditorPane editor = getEditor(e);
if (editor != null) {
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean strike = (StyleConstants.isStrikeThrough(attr)) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setStrikeThrough(sas, strike);
setCharacterAttributes(editor, sas, false);
}
}
示例3: highlight
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void highlight(ActionEvent e){
JEditorPane editor = getEditor(e);
if(editor != null){
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
javax.swing.text.DefaultHighlighter.DefaultHighlightPainter highlightPainter =
new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
try {
last = editor.getHighlighter().addHighlight(editor.getSelectionStart(), editor.getSelectionEnd(), highlightPainter);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
示例4: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isItalic(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setItalic(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例5: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isStrikeThrough(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setStrikeThrough(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例6: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isSubscript(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setSubscript(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例7: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isUnderline(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setUnderline(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例8: action
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
public void action()
{
JEditorPane ed = getEditor();
if(ed != null)
{
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet as = k.getInputAttributes();
boolean on = StyleConstants.isSuperscript(as);
SimpleAttributeSet a = new SimpleAttributeSet();
StyleConstants.setSuperscript(a, !on);
setCharacterAttributes(ed, a, false);
}
}
示例9: setCharacterAttributes
import javax.swing.text.StyledEditorKit; //導入方法依賴的package包/類
protected void setCharacterAttributes(JEditorPane ed, AttributeSet as, boolean replace)
{
int start = ed.getSelectionStart();
int end = ed.getSelectionEnd();
// word selection logic a-la MS Word
if(start == end)
{
int ws = getWordStart(ed, start);
if(ws >= 0)
{
int we = getWordEnd(ed, end);
if(we >= 0)
{
start = ws;
end = we;
}
}
}
if(start != end)
{
getStyledDocument(ed).setCharacterAttributes(start, end - start, as, replace);
}
StyledEditorKit k = getStyledEditorKit(ed);
MutableAttributeSet a = k.getInputAttributes();
if(replace)
{
a.removeAttributes(a);
}
a.addAttributes(as);
}