Java 8 StyleContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 StyleContext class.

This code example shows how to use the following methods:getFontMetrics
 
    /** 
     * Returns the width of the message in the given font. 
     */ 
    public static int getPixelWidth(String text, Font font) {
        StyleSheet css = new StyleSheet();
        FontMetrics fontMetrics = css.getFontMetrics(font);
        return fontMetrics.stringWidth(text);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getFontMetrics
    /** 
     * Returns the width of the message in the given font and editor kit. 
     */ 
    private int getAverageCharacterWidthInString(String text, Font font) {
        //TODO optimize 
        StyleSheet css = new StyleSheet();
        FontMetrics fontMetrics = css.getFontMetrics(font);
        int averageCharacterWidthForFont = (int)Math.ceil((fontMetrics.stringWidth(text) /(double) text.length()));
        return averageCharacterWidthForFont;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getFont, getForeground
        setOpaque(false);
        setName("RULE_" + name);
		this.ruleName = name;
        this.attributes = Diagram.lookupAttributes("identifier");
 
        StyleContext context = new StyleContext();
        setFont(context.getFont(this.attributes));
        setForeground(context.getForeground(attributes));
 
        String family = StyleConstants.getFontFamily(attributes);
        int size = StyleConstants.getFontSize(attributes);
        int x = 0;
	} 
 
    public String getRuleName() {
        return ruleName;
    } 
 
	@Override 
	public void paintComponent(Graphics g) {
4
CodeRank
This code example shows how to use the following methods:addAttribute, getEmptySet
	protected RedoAction redoAction = null;
    private Filter filter;
    private boolean unsavedChanges= false;
    private Pattern p = Pattern.compile("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)");
    final StyleContext cont = StyleContext.getDefaultStyleContext();
    final AttributeSet attr = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.GRAY);
    final AttributeSet attrBlack = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.BLACK);
    private DefaultStyledDocument doc;
    public CodeField() { 
        super(); 
    } 
     
    public void init(int size){
    	 this.setEditable(true);
    	this.setPreferredSize(new Dimension(550,500));
		this.setContentType("text/java");
		this.setText("");
		 
		doc = new DefaultStyledDocument();/* {
            public void insertString (int offset, String str, AttributeSet a) throws BadLocationException { 
3
CodeRank
See Code Examples for Java 8 StyleContext Methods: