Style defaultStyle = jtp.getStyle(StyleContext.DEFAULT_STYLE); doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, false);
/** * Sets the text pane. */ private void setTextPane() { Style defaultStyle = this.textPane.getStyle(defaultStyleName); // Style style = textPane.getStyle(typeName); // if (style == null || defaultStyle == null) { // System.out.println("Style is null."); // } Document doc = this.textPane.getDocument(); try { doc.remove(0, doc.getLength()); doc.insertString(doc.getLength(), "This is what an ", defaultStyle); doc.insertString(doc.getLength(), "annotation", this.currentStyle); doc.insertString(doc.getLength(), " of type ", defaultStyle); doc.insertString(doc.getLength(), this.currentTypeName, this.currentStyle); doc.insertString(doc.getLength(), " will look like.", defaultStyle); } catch (BadLocationException e) { // assert(false); } this.textPane.repaint(); }
@Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { rows.get(rowIndex)[columnIndex] = aValue; if (columnIndex == 2) { int start = (int) rows.get(rowIndex)[0]; int end = (int) rows.get(rowIndex)[1]; editorPane.getStyledDocument() .setCharacterAttributes(start, end - start, editorPane.getStyle(((Tag) rows.get(rowIndex)[2]).name()), true); fireTableCellUpdated(rowIndex, columnIndex); } }
style = pane.getStyle(match.group(1)); if (style == null) throw new IllegalArgumentException("Unknown style: '" + match.group(1));
private void refreshView() { LOGGER.info("refreshing view"); Style defaultStyle = textPane.getStyle(StyleContext.DEFAULT_STYLE); String text = textPane.getText(); textPane.getStyledDocument().setCharacterAttributes(0, text.length(), defaultStyle, true); try { PropertyPatternMessageColorizer propertyPatternMessageColorize = createMessageColorizer(); if (propertyPatternMessageColorize.colorizingNeeded(text)) { Collection<MessageFragmentStyle> colorize = propertyPatternMessageColorize.colorize(text); for (MessageFragmentStyle mfs : colorize) { textPane.getStyledDocument().setCharacterAttributes(mfs.getOffset(), mfs.getLength(), mfs.getStyle(), mfs.isReplace()); } } } catch (Exception e) { LOGGER.error(String.format("Can't init PropertyPatternMessageColorizer:%s", e.getMessage())); statusObserver.updateStatus(String.format("Error: %s", e.getMessage()), StatusObserver.LEVEL_ERROR); } }
@Override public void keyReleased(KeyEvent e) { if (e.isControlDown() && e.getKeyChar() == '+') { Font font = editorPane.getFont(); if (font.getSize() < 24) { Font f2 = new Font(font.getName(), font.getStyle(), font.getSize() + 2); editorPane.setFont(f2); StyleConstants.setFontSize(editorPane.getStyle(StyleContext.DEFAULT_STYLE), f2.getSize()); } } else if (e.isControlDown() && e.getKeyChar() == '-') { Font font = editorPane.getFont(); if (font.getSize() > 12) { Font f2 = new Font(font.getName(), font.getStyle(), font.getSize() - 2); editorPane.setFont(f2); } } savePreferences(); lines.setFont(new Font(Font.MONOSPACED, Font.PLAIN, editorPane.getFont().getSize())); super.keyPressed(e); } });
@Override protected void done() { try { String result = get(); if (result != null) { textPane.setText(""); StyledDocument doc = textPane.getStyledDocument(); doc.insertString(doc.getLength(), track.getTrackData().getArtist() + "\n", textPane.getStyle("artist")); doc.insertString(doc.getLength(), track.getTrackData().getTitle() + "\n\n", textPane.getStyle("title")); doc.insertString(doc.getLength(), Util.htmlToString(result), null); textPane.setCaretPosition(0); } } catch (Exception ignored) { } }
javax.swing.text.Style style = textpane.addStyle("Red", null); StyleConstants.setForeground(style, Color.RED); doc.setCharacterAttributes(0, 1, textpane.getStyle("Red"), true); panel.add(textpane); frame.add(panel);
@Override public void actionPerformed(ActionEvent e) { Track track = player.getTrack(); try { textPane.setText(""); StyledDocument doc = textPane.getStyledDocument(); doc.insertString(doc.getLength(), track.getTrackData().getArtist() + "\n", textPane.getStyle("artist")); doc.insertString(doc.getLength(), track.getTrackData().getTitle() + "\n\n", textPane.getStyle("title")); } catch (BadLocationException e1) { e1.printStackTrace(); } if (search != null && !search.isDone()) search.cancel(true); search = new Search(textPane, track); search.execute(); timer.stop(); } });
@Override public void actionPerformed(ActionEvent actionEvent) { doc.setCharacterAttributes(stringIndex, 1, textpane.getStyle("Red"), true); stringIndex++; try {
end = life; Style style = textPane.getStyle("negra");
private void addTag(Tag tag) { int start = editorPane.getSelectionStart(); int end = editorPane.getSelectionEnd(); if (annotationTableModel.spanHasAnnotation(start, end)) { if (JOptionPane.showConfirmDialog(null, "Delete existing annotations on span?") == JOptionPane.OK_OPTION) { annotationTableModel.annotations.overlapping(new Span(start, end)).forEach(a -> { int r = annotationTableModel.find(a.start(), a.end()); annotationTableModel.removeRow(r); }); } else { return; } } if (start == end) { return; } dirty = true; editorPane.getStyledDocument() .setCharacterAttributes(start, end - start, editorPane.getStyle(tag.name()), true); annotationTableModel.addRow(new Object[]{start, end, tag, editorPane.getSelectedText()}); }
public void run() { System.out.println("\t" + (System.currentTimeMillis() - start) + " ms - letter: " + TEXT.charAt(letterIndex)); doc.setCharacterAttributes(letterIndex, 1, textpane.getStyle("Red"), true);
Style defaultStyle = jtp.getStyle(StyleContext.DEFAULT_STYLE); doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, false);
start, len, textPane.getStyle("RED"), true);
.setCharacterAttributes(start, length, editorPane.getStyle(((Tag) row[2]).name()), true); });
textpane.getStyle("Red"), true);
doc.insertString(0,"Artist\tAlbum\tGernre\tGreatest Hit\tRecord Lable\n",textPane.getStyle("large")); doc.insertString(doc.getLength(),songs.get(j).getArtist() + "\t",textPane.getStyle("bold")); doc.insertString(doc.getLength(),songs.get(j).getAlbum() + "\t",textPane.getStyle("bold")); doc.insertString(doc.getLength(),songs.get(j).getGenre() + "\t",textPane.getStyle("bold")); doc.insertString(doc.getLength(),songs.get(j).getHit() + "\t",textPane.getStyle("italic")); doc.insertString(doc.getLength(),songs.get(j).getLable() + "\n",textPane.getStyle("regular"));
StyledDocument doc = (StyledDocument) textPane.getDocument(); Style normalStyle = textPane.getStyle("normal"); Style hyperlinkStyle = textPane.addStyle("hyperlink", normalStyle); StyleConstants.setForeground(hyperlinkStyle, LINK_COLOR == null ? Color.BLUE : LINK_COLOR);