List of usage examples for javax.swing JTextPane JTextPane
public JTextPane()
JTextPane
. From source file:Main.java
public Main() { setSize(300, 200);// w w w.jav a 2 s .c o m setDefaultCloseOperation(EXIT_ON_CLOSE); final JTextPane textPane = new JTextPane(); add(textPane); textPane.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { Highlight[] h = textPane.getHighlighter().getHighlights(); for (int i = 0; i < h.length; i++) { System.out.println(h[i].getStartOffset()); System.out.println(h[i].getEndOffset()); } } }); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); setContentPane(panel);/* w ww. j av a 2 s .c o m*/ JTextPane textA = new JTextPane(); textA.setName("text"); textA.setContentType("text/html"); DefaultCaret caret = (DefaultCaret) textA.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler = new JScrollPane(textA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JTextPane textB = new JTextPane(); textB.setName("text" + "_T"); textB.setFont(textA.getFont()); DefaultCaret caret_T = (DefaultCaret) textB.getCaret(); caret_T.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler_T = new JScrollPane(textB, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); panel.add(filler, BorderLayout.NORTH); panel.add(filler_T, BorderLayout.CENTER); pack(); }
From source file:UndoExample1.java
public UndoExample1() { super("Undo/Redo Example 1"); pane = new JTextPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Add a menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar);// ww w. j av a 2 s. c o m // Populate the menu bar createMenuBar(); }
From source file:Main.java
public TestPane() { setLayout(new BorderLayout()); setBorder(new EmptyBorder(10, 10, 10, 10)); JTextPane pane = new JTextPane(); JPanel panel = new JPanel(new BorderLayout()); JPanel innerPanel = new JPanel(new BorderLayout()); pane.setBorder(BorderFactory.createLineBorder(Color.BLACK)); innerPanel.add(pane);/* w w w.j a va 2 s . co m*/ panel.add(innerPanel); add(panel); }
From source file:Main.java
private void createAndDisplayGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tPane = new JTextPane(); JScrollPane scroller = new JScrollPane(); scroller.setViewportView(tPane);/* w w w . j a v a2 s. com*/ tfield.addActionListener(e -> { counter++; if (counter == 8) counter = 0; String text = tfield.getText() + "\n"; appendToPane(tPane, text, colours[counter]); tfield.selectAll(); }); getContentPane().add(scroller, BorderLayout.CENTER); getContentPane().add(tfield, BorderLayout.PAGE_END); setSize(200, 100); setVisible(true); tfield.requestFocusInWindow(); tfield.setText("hi enter to start"); }
From source file:Main.java
public void build() { setSize(600, 600);/*from ww w . j a v a 2s.c o m*/ JTextPane textPane = new JTextPane(); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); JTextArea changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); JPanel statusPane = new JPanel(new GridLayout(1, 1)); JLabel caretListenerLabel = new JLabel("Caret Status"); statusPane.add(caretListenerLabel); JToolBar toolBar = new JToolBar(); toolBar.add(new JButton("Btn1")); toolBar.add(new JButton("Btn2")); toolBar.add(new JButton("Btn3")); toolBar.add(new JButton("Btn4")); getContentPane().add(toolBar, BorderLayout.PAGE_START); getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); JMenu editMenu = new JMenu("test"); JMenu styleMenu = new JMenu("test"); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); }
From source file:UndoStyleFrame.java
public UndoStyleFrame() { super();//from w ww. j a v a 2 s .c o m setTitle("UndoStyleFrame"); JTextPane textPane = new JTextPane(); textPane.getDocument().addUndoableEditListener(undoAction); textPane.getDocument().addUndoableEditListener(redoAction); JMenu editMenu = new JMenu("Edit"); editMenu.add(new JMenuItem(undoAction)); editMenu.add(new JMenuItem(redoAction)); JMenuBar menuBar = new JMenuBar(); menuBar.add(editMenu); setJMenuBar(menuBar); JPanel buttonPanel = new JPanel(); buttonPanel.add(new JButton(undoAction)); buttonPanel.add(new JButton(redoAction)); getContentPane().add(textPane, "Center"); getContentPane().add(buttonPanel, "South"); }
From source file:Main.java
public TextPaneAttributes() { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, 0, standard, true); MutableAttributeSet keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.red); StyleConstants.setItalic(keyWord, true); textPane.setText("this is a test. \nthis is a four."); doc.setCharacterAttributes(0, 3, keyWord, false); doc.setCharacterAttributes(19, 4, keyWord, false); try {//from ww w . j a v a2s .c o m doc.insertString(0, "Start of text\n", null); doc.insertString(doc.getLength(), "End of text\n", keyWord); } catch (Exception e) { } MutableAttributeSet selWord = new SimpleAttributeSet(); StyleConstants.setForeground(selWord, Color.RED); StyleConstants.setItalic(selWord, true); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); add(scrollPane); JButton toggleButton = new JButton("Find 'four'"); toggleButton.addActionListener(e -> { int index = textPane.getText().indexOf("four"); StyledDocument doc1 = textPane.getStyledDocument(); doc1.setCharacterAttributes(index, 4, selWord, false); }); add(toggleButton, BorderLayout.SOUTH); }
From source file:UndoEditor.java
public UndoEditor() { setLayout(new BorderLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane editor = new JTextPane(); editor.getDocument().addUndoableEditListener(new UndoListener()); menuBar.add(editMenu);// www .j ava2 s .c o m editMenu.add(undoAction); editMenu.add(redoAction); this.setJMenuBar(menuBar); add(new JScrollPane(editor)); setSize(400, 300); setVisible(true); }
From source file:UndoEditor.java
public UndoEditor() { setLayout(new BorderLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane editor = new JTextPane(); editor.getDocument().addUndoableEditListener(new UndoListener()); JScrollPane scroller = new JScrollPane(editor); menuBar.add(editMenu);/*w w w . j a va2 s .com*/ editMenu.add(undoAction); editMenu.add(redoAction); this.setJMenuBar(menuBar); add(scroller); setSize(400, 300); setVisible(true); }