SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground(sas, Color.YELLOW); doc.setCharacterAttributes(start, length, sas, false);
private AttributeSet getAttributeSet(String tag) { MutableAttributeSet attr = new SimpleAttributeSet(); Color color = tagToColorMap.get(tag); StyleConstants.setBackground(attr, color); StyleConstants.setForeground(attr, Color.WHITE); return attr; }
private AttributeSet getAttributeSet(String tag) { MutableAttributeSet attr = new SimpleAttributeSet(); Color color = tagToColorMap.get(tag); StyleConstants.setBackground(attr, color); StyleConstants.setForeground(attr, Color.WHITE); return attr; }
StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false);
JTextPane textPane = new JTextPane(); textPane.setText( "original text" ); StyledDocument doc = textPane.getStyledDocument(); // Define a keyword attribute SimpleAttributeSet keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.RED); StyleConstants.setBackground(keyWord, Color.YELLOW); StyleConstants.setBold(keyWord, true); // Add some text try { doc.insertString(0, "Start of text\n", null ); doc.insertString(doc.getLength(), "\nEnd of text", keyWord ); } catch(Exception e) { System.out.println(e); }
private void removeTags() { if (editorPane.getContentType().equals("text/html")) { editorPane.setText(htmlContents); editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
final SimpleAttributeSet styles = new SimpleAttributeSet(); SwingWorker<String, Void> inputWorker = new SwingWorker<String, Void>() { @Override
private void removeTags() { if (editorPane.getContentType().equals("text/html")) { if (htmlContents != null) { editorPane.setText(htmlContents); } editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
private JComponent createNoPlannerFoundTextField() { String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory (" + benchmarkAggregator.getBenchmarkDirectory() + ")."; JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setText(infoMessage); // center info message StyledDocument styledDocument = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); StyleConstants.setBold(center, true); styledDocument.setParagraphAttributes(0, styledDocument.getLength(), center, false); return textPane; }
/** * Creates new form ParserPanel */ public ParserPanel() { initComponents(); // create dialogs for file selection jfc = new JFileChooser(System.getProperty("user.dir")); pageDialog = new OpenPageDialog(new Frame(), true); pageDialog.setFileChooser(jfc); jfcLocation = new JFileChooserLocation(jfc); tlp = new PennTreebankLanguagePack(); encoding = tlp.getEncoding(); setFont(); // create a timer timer = new javax.swing.Timer(ONE_SECOND, new TimerListener()); // for (un)highlighting text highlightStyle = new SimpleAttributeSet(); normalStyle = new SimpleAttributeSet(); StyleConstants.setBackground(highlightStyle, Color.yellow); StyleConstants.setBackground(normalStyle, textPane.getBackground()); this.chooseJarParser = new JarFileChooser(".*\\.ser\\.gz", this); }
/** * Write a line to the Log section of the GUI * * @param text the string to log * @param color the color of the line */ private void appendLog(final String text, final Color color) { SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground(sas, color); StyledDocument sd = logText.getStyledDocument(); try { synchronized (this) { sd.insertString(sd.getLength(), text + "\n", sas); } } catch (BadLocationException e) { } logText.setCaretPosition(sd.getLength()); }
int left = 10; int right = 10; SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setAlignment(set, StyleConstants.ALIGN_LEFT); StyleConstants.setSpaceAbove(set, top);
background = new SimpleAttributeSet(); StyleConstants.setBackground(background, Color.RED);
SimpleAttributeSet set = new SimpleAttributeSet();
private static void addStyle(String name, Color bg, Color fg, boolean bold, boolean italic) { SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setFontFamily(style, HelperUi.FONT_UBUNTU_MONO.getFontName()); StyleConstants.setFontSize(style, HelperUi.FONT_UBUNTU_MONO.getSize()); StyleConstants.setBackground(style, bg); StyleConstants.setForeground(style, fg); StyleConstants.setBold(style, bold); StyleConstants.setItalic(style, italic); styles.put(name, style); }
SimpleAttributeSet normal = new SimpleAttributeSet(); StyleConstants.setFontFamily(normal, "Serif"); StyleConstants.setFontSize(normal, 72);
SimpleAttributeSet levelStyle = new SimpleAttributeSet(); switch (level) SimpleAttributeSet nameStyle = new SimpleAttributeSet(); StyleConstants.setForeground(nameStyle, new Color(0x6A6A6A));
SimpleAttributeSet green = new SimpleAttributeSet(); StyleConstants.setFontFamily(green, "Courier New Italic"); StyleConstants.setForeground(green, Color.GREEN); // Add some text try { textPane.getDocument().insertString(0, "green text with Courier font", green); } catch(Exception e) {}
protected MutableAttributeSet getMessageStyle() { final MutableAttributeSet style = new SimpleAttributeSet(); StyleConstants.setFontFamily( style, "Dialog" ); StyleConstants.setFontSize( style, SettingsManager.getLocalPreferences().getChatRoomFontSize() ); StyleConstants.setForeground( style, messageColor ); StyleConstants.setBackground( style, backgroundColor ); return style; }
protected AttributeSet getStyle() { final MutableAttributeSet style = new SimpleAttributeSet(); StyleConstants.setFontFamily( style, "Dialog" ); StyleConstants.setFontSize( style, SettingsManager.getLocalPreferences().getChatRoomFontSize() ); StyleConstants.setForeground( style, textColor ); StyleConstants.setBold( style, bold ); StyleConstants.setItalic( style, italic ); StyleConstants.setUnderline( style, underline ); StyleConstants.setStrikeThrough( style, strikeThrough ); return style; }