/** * Returns the specified font. * * @param family The font family. * @param style The style of font. * @param size The size of the font. * @return The font. */ private static Font getFont(String family, int style, int size) { // Use StyleContext to get a composite font for Asian glyphs. StyleContext sc = StyleContext.getDefaultStyleContext(); return sc.getFont(family, style, size); }
font = sc.getFont("Menlo", Font.PLAIN, 12); if (!"Menlo".equals(font.getFamily())) { font = sc.getFont("Monaco", Font.PLAIN, 12); if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen font = sc.getFont("Monospaced", Font.PLAIN, 13); font = sc.getFont("Consolas", Font.PLAIN, 13); if (!"Consolas".equals(font.getFamily())) { font = sc.getFont("Monospaced", Font.PLAIN, 13);
/** * Changes the "base font" for this syntax scheme. This is called by * <code>RSyntaxTextArea</code> when its font changes via * <code>setFont()</code>. This looks for tokens that use a derivative of * the text area's old font (but bolded and/or italicized) and make them * use the new font with those stylings instead. This is desirable because * most programmers prefer a single font to be used in their text editor, * but might want bold (say for keywords) or italics. * * @param old The old font of the text area. * @param font The new font of the text area. */ void changeBaseFont(Font old, Font font) { for (int i=0; i<styles.length; i++) { Style style = styles[i]; if (style!=null && style.font!=null) { if (style.font.getFamily().equals(old.getFamily()) && style.font.getSize()==old.getSize()) { int s = style.font.getStyle(); // Keep bold or italic StyleContext sc = StyleContext.getDefaultStyleContext(); style.font= sc.getFont(font.getFamily(), s, font.getSize()); } } } }
String family = tokens[pos+4]; if (!"-".equals(family)) { font = sc.getFont(family, Integer.parseInt(tokens[pos+5]), // style Integer.parseInt(tokens[pos+6])); // size
public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); return styles.getFont(attr); }
/** * Returns the specified font. * * @param family The font family. * @param style The style of font. * @param size The size of the font. * @return The font. */ private static Font getFont(String family, int style, int size) { // Use StyleContext to get a composite font for Asian glyphs. StyleContext sc = StyleContext.getDefaultStyleContext(); return sc.getFont(family, style, size); }
font = sc.getFont("Menlo", Font.PLAIN, 12); if (!"Menlo".equals(font.getFamily())) { font = sc.getFont("Monaco", Font.PLAIN, 12); if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen font = sc.getFont("Monospaced", Font.PLAIN, 13); font = sc.getFont("Consolas", Font.PLAIN, 13); if (!"Consolas".equals(font.getFamily())) { font = sc.getFont("Monospaced", Font.PLAIN, 13);
/** * Changes the "base font" for this syntax scheme. This is called by * <code>RSyntaxTextArea</code> when its font changes via * <code>setFont()</code>. This looks for tokens that use a derivative of * the text area's old font (but bolded and/or italicized) and make them * use the new font with those stylings instead. This is desirable because * most programmers prefer a single font to be used in their text editor, * but might want bold (say for keywords) or italics. * * @param old The old font of the text area. * @param font The new font of the text area. */ void changeBaseFont(Font old, Font font) { for (int i=0; i<styles.length; i++) { Style style = styles[i]; if (style!=null && style.font!=null) { if (style.font.getFamily().equals(old.getFamily()) && style.font.getSize()==old.getSize()) { int s = style.font.getStyle(); // Keep bold or italic StyleContext sc = StyleContext.getDefaultStyleContext(); style.font= sc.getFont(font.getFamily(), s, font.getSize()); } } } }
/** * Changes the "base font" for this syntax scheme. This is called by * <code>RSyntaxTextArea</code> when its font changes via * <code>setFont()</code>. This looks for tokens that use a derivative of * the text area's old font (but bolded and/or italicized) and make them * use the new font with those stylings instead. This is desirable because * most programmers prefer a single font to be used in their text editor, * but might want bold (say for keywords) or italics. * * @param old The old font of the text area. * @param font The new font of the text area. */ void changeBaseFont(Font old, Font font) { for (int i=0; i<styles.length; i++) { Style style = styles[i]; if (style!=null && style.font!=null) { if (style.font.getFamily().equals(old.getFamily()) && style.font.getSize()==old.getSize()) { int s = style.font.getStyle(); // Keep bold or italic StyleContext sc = StyleContext.getDefaultStyleContext(); style.font= sc.getFont(font.getFamily(), s, font.getSize()); } } } }
HeaderPanel() { setLayout(new BorderLayout()); JPanel headerPanel = new JPanel(new BorderLayout()); headerPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,5,0), new LineDividerBorder(SwingConstants.BOTTOM))); header = new JLabel("Header"); // WORKAROUND for Sun JRE bug 6282887 (for JRE's pre-1.5.0-b45). //Font font = header.getFont().deriveFont(Font.BOLD, 18); StyleContext sc = StyleContext.getDefaultStyleContext(); Font font = header.getFont(); font = sc.getFont(font.getFamily(), Font.BOLD, 18); header.setFont(font); headerPanel.add(header, BorderLayout.WEST); add(headerPanel, BorderLayout.NORTH); }
String family = tokens[pos+4]; if (!"-".equals(family)) { font = sc.getFont(family, Integer.parseInt(tokens[pos+5]), // style Integer.parseInt(tokens[pos+6])); // size
Font f = styles.getFont(attr); String ff = f.getFamily(); System.out.println(ff);