Refine search
private void buildContentPanel() { editorPane = new JEditorPane (); editorPane.setContentType("text/rtf"); editorPane.addKeyListener(new InputListener()); // defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes(); StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans"); Document doc = new DefaultStyledDocument(); editorPane.setDocument(doc); try { doc.insertString(0, initText, defaultAttrSet); } catch (Exception ex) { throw new RuntimeException(ex); } JScrollPane scrollPane = new JScrollPane(editorPane); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); editorPane.setEditable(true); }
String text = null; try { text = doc.getText(0, doc.getLength()); } catch (Exception e) { throw new RuntimeException(e); try { String entity = finalText.substring(start, end); doc.setCharacterAttributes(start, entity.length(), attSet, false); } catch (Exception ex) { throw new RuntimeException(ex);
DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); // set some style properties StyleConstants.setForeground(style, Color.BLUE); // add some data to the document document.insertString(0, "", style);
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); }
styledDocument.setCharacterAttributes(matchEnd, offset - matchEnd, defaultStyle, styledDocument.setCharacterAttributes(offset, matchEnd - offset, style, true); if (styledDocument.getParagraphElement(offset).getStartOffset() != styledDocument.getParagraphElement(matchEnd).getStartOffset()) { styledDocument.setCharacterAttributes(matchEnd, checkPoint - matchEnd, defaultStyle,
private JEditorPane editorPane = new JEditorPane(); private JComboBox<Integer> fontBox = new JComboBox<Integer>(ITEMS); private StyledDocument doc = new DefaultStyledDocument(); private StyledEditorKit styledEditorKit = new StyledEditorKit(); editorPane.setDocument(doc); editorPane.setEditorKit(styledEditorKit); JScrollPane scrollpane = new JScrollPane(editorPane); scrollpane.setPreferredSize(new Dimension(500, 400)); JPanel comboPanel = new JPanel(); comboPanel.add(fontBox); setLayout(new BorderLayout()); add(scrollpane, BorderLayout.CENTER); add(comboPanel, BorderLayout.SOUTH); JFrame frame = new JFrame("EditorPaneFun"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new EditorPaneFun()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
JFrame frame = new JFrame(TestDifferentStyles.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument doc = new DefaultStyledDocument(); JTextPane textPane = new JTextPane(doc); textPane.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has " + "been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of " frame.add(new JScrollPane(textPane)); frame.setSize(500, 400); frame.setVisible(true);
JFrame f = new JFrame("Styles Example 1"); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); JTextPane pane = new JTextPane(doc); doc.setParagraphAttributes(0, 1, heading2Style, false); } catch (BadLocationException e) { f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(600,200)); frame.getContentPane().setBackground(Color.BLACK); panel.setLayout(new GridLayout(1, 2)); panel.setBackground(Color.BLACK); frame.add(panel); StyledDocument document = new DefaultStyledDocument(context); JTextPane area = new JTextPane(document); panel.add(area); frame.setVisible(true);
public void run() { JFrame frame = initgui(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); JFrame frame = new JFrame("Test"); JPanel panel = new JPanel(); StyledDocument doc = (StyledDocument) new DefaultStyledDocument(); JTextPane textpane = new JTextPane(doc); textpane.setText("Test"); 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); return frame;
setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 400); setLocationRelativeTo(null); if (wordR == after || String.valueOf(text.charAt(wordR)).matches("\\W")) { if (text.substring(wordL, wordR).matches("(\\W)*(private|public|protected)")) setCharacterAttributes(wordL, wordR - wordL, attr, false); else setCharacterAttributes(wordL, wordR - wordL, attrBlack, false); wordL = wordR; setCharacterAttributes(before, after - before, attr, false); } else { setCharacterAttributes(before, after - before, attrBlack, false); JTextPane txt = new JTextPane(doc); txt.setText("public class Hi {}"); add(new JScrollPane(txt)); setVisible(true);
JFrame f = new JFrame("Cool Table"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(t)); f.pack(); f.setVisible(true); if(data[r] instanceof String) { try{ DefaultStyledDocument doc = new DefaultStyledDocument(); doc.insertString(0, data[r].toString(), null); data[r] = doc; private static Border etchedBorder = BorderFactory.createEtchedBorder(); private JTextComponent styledRenderer = new JTextPane(); private JTextPane styledEditor = new JTextPane(); editorComponent = new JScrollPane(styledEditor); styledEditor.setDocument((Document)val);
this.styledDocument = new DefaultStyledDocument(); this.styledDocument.insertString(0, displayText(), null); addStylesToDocument(styledDocument); JFrame frame = new JFrame("JTextPane Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); textPane = new JTextPane(styledDocument); textPane.addCaretListener(new SelectedText()); textPane.setPreferredSize(new Dimension(250, 125)); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane); frame.pack(); frame.setVisible(true);
this.document = new DefaultStyledDocument(); Runnable runnable = new Runnable() { @Override frame = new JFrame(); frame.setTitle("Huge Text"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textArea)); frame.setSize(400, 350); frame.setLocationRelativeTo(null); frame.setVisible(true);
JTextPane textPane = new JTextPane(new DefaultStyledDocument()); ((AbstractDocument) textPane.getDocument()).setDocumentFilter(new HighlightDocumentFilter(textPane)); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(textPane)); frame.pack();
JFrame frame = new JFrame(); DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane pane = new JTextPane(document); JPanel mainPanel = new JPanel(); JButton button = new JButton("Button"); button.setPreferredSize(new Dimension(100, 40)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pane.setPreferredSize(new Dimension(200, 200)); mainPanel.add(button); frame.getContentPane().add(pane, BorderLayout.CENTER); frame.getContentPane().add(mainPanel, BorderLayout.WEST); StyleContext context = new StyleContext(); frame.pack(); frame.setVisible(true);
@Override public void run() { JFrame frame = new JFrame("Colored Text"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument doc = new DefaultStyledDocument(); JTextPane textPane = new JTextPane(doc); textPane.setText("Different Colored Text"); for (int i = 0; i < textPane.getDocument().getLength(); i++) { SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, frame.add(new JScrollPane(textPane)); frame.pack(); frame.setVisible(true);
add(leftBox); DefaultStyledDocument pd = new DefaultStyledDocument(); SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setSpaceBelow(sas, spaceBelow); pd.setParagraphAttributes(0, pd.getLength(), sas, false); modifiedTA= new JTextPane(pd); add(modifiedTA); final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new LineSpacingExample()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
StyleConstants.setFontFamily(style, "Helvetica"); printStyleAttributes(style); document.setCharacterAttributes(0, document.getLength(), style, true); }); JFrame frame = new JFrame("Styling example"); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(editorPane); contentPane.add(changeStyleButton); frame.setContentPane(contentPane); frame.setSize(300,300); frame.setLocationRelativeTo(null); frame.setVisible(true);