Java Code Examples for javax.swing.JTextArea#getHighlighter()
The following examples show how to use
javax.swing.JTextArea#getHighlighter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiffDialog.java From zap-extensions with Apache License 2.0 | 6 votes |
private int appendText(JTextArea area, String text, boolean highlight) { int start = area.getDocument().getLength(); if (text == null || text.length() == 0) { return start; } int end = start + text.length(); try { area.getDocument().insertString(start, text, null); if (highlight) { Highlighter hilite = area.getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); hilite.addHighlight(start, end - 1, painter); } } catch (BadLocationException e) { logger.error(e.getMessage(), e); } return end; }
Example 2
Source File: DiffDialog.java From zap-extensions with Apache License 2.0 | 5 votes |
private void highlightText(JTextArea area, int start, int end) { Highlighter hilite = area.getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); try { hilite.addHighlight(start, end, painter); } catch (BadLocationException e) { logger.error(e.getMessage(), e); } }
Example 3
Source File: CorefEditor.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * This method intiates the GUI for co-reference editor */ @Override protected void initGUI() { //get a pointer to the textual view used for highlights Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator(); while (textView == null && centralViewsIter.hasNext()) { DocumentView aView = centralViewsIter.next(); if (aView instanceof TextualDocumentView) textView = (TextualDocumentView) aView; } textPane = (JTextArea) ( (JScrollPane) textView.getGUI()).getViewport(). getView(); highlighter = textPane.getHighlighter(); chainToolTipAction = new ChainToolTipAction(); chainToolTipTimer = new javax.swing.Timer(500, chainToolTipAction); chainToolTipTimer.setRepeats(false); newCorefAction = new NewCorefAction(); newCorefActionTimer = new javax.swing.Timer(500, newCorefAction); newCorefActionTimer.setRepeats(false); colorGenerator = new ColorGenerator(); // main Panel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); // topPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); // subPanel subPanel = new JPanel(); subPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // showAnnotations Button showAnnotations = new JToggleButton("Show"); showAnnotations.addActionListener(this); // annotSets annotSets = new JComboBox<String>(); annotSets.addActionListener(this); // get all the annotationSets Map<String,AnnotationSet> annotSetsMap = document.getNamedAnnotationSets(); annotSetsModel = new DefaultComboBoxModel<String>(); if (annotSetsMap != null) { String [] array = annotSetsMap.keySet().toArray(new String[annotSetsMap.keySet().size()]); for(int i=0;i<array.length;i++) { annotSetsMap.get(array[i]).addAnnotationSetListener(this); } annotSetsModel = new DefaultComboBoxModel<String>(array); } document.getAnnotations().addAnnotationSetListener(this); annotSetsModel.insertElementAt(DEFAULT_ANNOTSET_NAME, 0); annotSets.setModel(annotSetsModel); // annotTypes annotTypesModel = new DefaultComboBoxModel<String>(); annotTypes = new JComboBox<String>(annotTypesModel); annotTypes.addActionListener(this); subPanel.add(new JLabel("Sets : ")); subPanel.add(annotSets); JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); tempPanel.add(new JLabel("Types : ")); tempPanel.add(annotTypes); tempPanel.add(showAnnotations); // intialises the Data initData(); // and creating the tree corefTree = new JTree(rootNode); corefTree.putClientProperty("JTree.lineStyle", "None"); corefTree.setRowHeight(corefTree.getRowHeight() * 2); corefTree.setLargeModel(true); corefTree.setAutoscrolls(true); //corefTree.setRootVisible(false); //corefTree.setShowsRootHandles(false); corefTree.addMouseListener(new CorefTreeMouseListener()); corefTree.setCellRenderer(new CorefTreeCellRenderer()); mainPanel.add(topPanel, BorderLayout.NORTH); mainPanel.add(new JScrollPane(corefTree), BorderLayout.CENTER); topPanel.add(subPanel, BorderLayout.CENTER); topPanel.add(tempPanel, BorderLayout.SOUTH); // get the highlighter textPaneMouseListener = new TextPaneMouseListener(); annotSets.setSelectedIndex(0); // finally show the tree //annotSetSelectionChanged(); document.addDocumentListener(this); document.getFeatures().addFeatureMapListener(this); }