List of usage examples for javax.swing.text StyleConstants setFontFamily
public static void setFontFamily(MutableAttributeSet a, String fam)
From source file:Main.java
@Override public void run() { for (int i = 0; i < fnt.length; i++) { StyleConstants.setBold(mas, false); StyleConstants.setItalic(mas, false); StyleConstants.setFontFamily(mas, fnt[i]); StyleConstants.setFontSize(mas, 16); dis(fnt[i]);/*from w w w. ja va 2s . c o m*/ try { Thread.sleep(75); } catch (Exception e) { e.printStackTrace(); } StyleConstants.setBold(mas, true); dis(fnt[i] + " Bold"); try { Thread.sleep(75); } catch (Exception e) { e.printStackTrace(); } } jta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
protected void addStylesToDocument(StyledDocument doc) { //Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); s = doc.addStyle("right", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_RIGHT); }
From source file:de.tor.tribes.ui.wiz.ret.RetimerCalculationPanel.java
/** * Creates new form AttackSourcePanel/*ww w . j a v a2 s . c om*/ */ RetimerCalculationPanel() { initComponents(); jXCollapsiblePane1.setLayout(new BorderLayout()); jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER); jInfoTextPane.setText(GENERAL_INFO); StyledDocument doc = (StyledDocument) jTextPane1.getDocument(); Style defaultStyle = doc.addStyle("Default", null); StyleConstants.setItalic(defaultStyle, true); StyleConstants.setFontFamily(defaultStyle, "SansSerif"); dateFormat = new SimpleDateFormat("HH:mm:ss"); retimes = new LinkedList<>(); }
From source file:de.tor.tribes.ui.wiz.ref.SupportRefillCalculationPanel.java
/** * Creates new form AttackSourcePanel/*w w w. java2 s . c o m*/ */ SupportRefillCalculationPanel() { initComponents(); jXCollapsiblePane1.setLayout(new BorderLayout()); jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER); jInfoTextPane.setText(GENERAL_INFO); StyledDocument doc = (StyledDocument) jTextPane1.getDocument(); Style defaultStyle = doc.addStyle("Default", null); StyleConstants.setItalic(defaultStyle, true); StyleConstants.setFontFamily(defaultStyle, "SansSerif"); dateFormat = new SimpleDateFormat("HH:mm:ss"); }
From source file:FontPicker.java
public void actionPerformed(ActionEvent ae) { // Check the name of the font if (!StyleConstants.getFontFamily(attributes).equals(fontName.getSelectedItem())) { StyleConstants.setFontFamily(attributes, (String) fontName.getSelectedItem()); }/*from w w w.java 2 s . co m*/ // Check the font size (no error checking yet) if (StyleConstants.getFontSize(attributes) != Integer.parseInt(fontSize.getText())) { StyleConstants.setFontSize(attributes, Integer.parseInt(fontSize.getText())); } // Check to see if the font should be bold if (StyleConstants.isBold(attributes) != fontBold.isSelected()) { StyleConstants.setBold(attributes, fontBold.isSelected()); } // Check to see if the font should be italic if (StyleConstants.isItalic(attributes) != fontItalic.isSelected()) { StyleConstants.setItalic(attributes, fontItalic.isSelected()); } // and update our preview label updatePreviewFont(); }
From source file:MainClass.java
public void actionPerformed(ActionEvent e) { JTextPane editor = (JTextPane) getEditor(e); int p0 = editor.getSelectionStart(); StyledDocument doc = getStyledDocument(editor); Element paragraph = doc.getCharacterElement(p0); AttributeSet as = paragraph.getAttributes(); family = StyleConstants.getFontFamily(as); fontSize = StyleConstants.getFontSize(as); formatText = new JDialog(new JFrame(), "Font and Size", true); formatText.getContentPane().setLayout(new BorderLayout()); JPanel choosers = new JPanel(); choosers.setLayout(new GridLayout(2, 1)); JPanel fontFamilyPanel = new JPanel(); fontFamilyPanel.add(new JLabel("Font")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); fontFamilyChooser = new JComboBox(); for (int i = 0; i < fontNames.length; i++) { fontFamilyChooser.addItem(fontNames[i]); }/*from www . j a v a 2 s . c om*/ fontFamilyChooser.setSelectedItem(family); fontFamilyPanel.add(fontFamilyChooser); choosers.add(fontFamilyPanel); JPanel fontSizePanel = new JPanel(); fontSizePanel.add(new JLabel("Size")); fontSizeChooser = new JComboBox(); fontSizeChooser.setEditable(true); fontSizeChooser.addItem(new Float(4)); fontSizeChooser.addItem(new Float(8)); fontSizeChooser.addItem(new Float(12)); fontSizeChooser.addItem(new Float(16)); fontSizeChooser.addItem(new Float(20)); fontSizeChooser.addItem(new Float(24)); fontSizeChooser.setSelectedItem(new Float(fontSize)); fontSizePanel.add(fontSizeChooser); choosers.add(fontSizePanel); JButton ok = new JButton("OK"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { accept = true; formatText.dispose(); family = (String) fontFamilyChooser.getSelectedItem(); fontSize = Float.parseFloat(fontSizeChooser.getSelectedItem().toString()); } }); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { formatText.dispose(); } }); JPanel buttons = new JPanel(); buttons.add(ok); buttons.add(cancel); formatText.getContentPane().add(choosers, BorderLayout.CENTER); formatText.getContentPane().add(buttons, BorderLayout.SOUTH); formatText.pack(); formatText.setVisible(true); MutableAttributeSet attr = null; if (editor != null && accept) { attr = new SimpleAttributeSet(); StyleConstants.setFontFamily(attr, family); StyleConstants.setFontSize(attr, (int) fontSize); setCharacterAttributes(editor, attr, false); } }
From source file:TextSamplerDemo.java
protected void addStylesToDocument(StyledDocument doc) { //Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); s = doc.addStyle("small", regular); StyleConstants.setFontSize(s, 10); s = doc.addStyle("large", regular); StyleConstants.setFontSize(s, 16); s = doc.addStyle("icon", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon pigIcon = createImageIcon("images/Pig.gif", "a cute pig"); if (pigIcon != null) { StyleConstants.setIcon(s, pigIcon); }//from ww w. j av a 2 s . c om s = doc.addStyle("button", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon soundIcon = createImageIcon("images/sound.gif", "sound icon"); JButton button = new JButton(); if (soundIcon != null) { button.setIcon(soundIcon); } else { button.setText("BEEP"); } button.setCursor(Cursor.getDefaultCursor()); button.setMargin(new Insets(0, 0, 0, 0)); button.setActionCommand(buttonString); button.addActionListener(this); StyleConstants.setComponent(s, button); }
From source file:TextComponentDemo.java
protected SimpleAttributeSet[] initAttributes(int length) { // Hard-code some attributes. SimpleAttributeSet[] attrs = new SimpleAttributeSet[length]; attrs[0] = new SimpleAttributeSet(); StyleConstants.setFontFamily(attrs[0], "SansSerif"); StyleConstants.setFontSize(attrs[0], 16); attrs[1] = new SimpleAttributeSet(attrs[0]); StyleConstants.setBold(attrs[1], true); attrs[2] = new SimpleAttributeSet(attrs[0]); StyleConstants.setItalic(attrs[2], true); attrs[3] = new SimpleAttributeSet(attrs[0]); StyleConstants.setFontSize(attrs[3], 20); attrs[4] = new SimpleAttributeSet(attrs[0]); StyleConstants.setFontSize(attrs[4], 12); attrs[5] = new SimpleAttributeSet(attrs[0]); StyleConstants.setForeground(attrs[5], Color.red); return attrs; }
From source file:TextComponentDemo.java
protected SimpleAttributeSet[] initAttributes(int length) { //Hard-code some attributes. SimpleAttributeSet[] attrs = new SimpleAttributeSet[length]; attrs[0] = new SimpleAttributeSet(); StyleConstants.setFontFamily(attrs[0], "SansSerif"); StyleConstants.setFontSize(attrs[0], 16); attrs[1] = new SimpleAttributeSet(attrs[0]); StyleConstants.setBold(attrs[1], true); attrs[2] = new SimpleAttributeSet(attrs[0]); StyleConstants.setItalic(attrs[2], true); attrs[3] = new SimpleAttributeSet(attrs[0]); StyleConstants.setFontSize(attrs[3], 20); attrs[4] = new SimpleAttributeSet(attrs[0]); StyleConstants.setFontSize(attrs[4], 12); attrs[5] = new SimpleAttributeSet(attrs[0]); StyleConstants.setForeground(attrs[5], Color.red); return attrs; }
From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java
private void addStylesToDocument() { //Initialize some styles. Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regularStyle = document.addStyle("regular", defaultStyle); StyleConstants.setFontFamily(defaultStyle, "SansSerif"); StyleConstants.setFontSize(defaultStyle, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE)); Style s = document.addStyle("used", regularStyle); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.blue); s = document.addStyle("marked", regularStyle); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.red); }