Java Code Examples for javax.swing.text.DefaultCaret#setUpdatePolicy()
The following examples show how to use
javax.swing.text.DefaultCaret#setUpdatePolicy() .
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: LogPanel.java From workcraft with MIT License | 6 votes |
public LogPanel() { textArea.setLineWrap(true); textArea.setEditable(false); textArea.setWrapStyleWord(true); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(textArea); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); textArea.addPopupMenu(); }
Example 2
Source File: SmartScroller.java From 07kit with GNU General Public License v3.0 | 5 votes |
/** * Specify how the SmartScroller will function. * * @param scrollPane the scroll pane to monitor * @param scrollDirection indicates which JScrollBar to monitor. * Valid values are HORIZONTAL and VERTICAL. * @param viewportPosition indicates where the viewport will normally be * positioned as data is added. * Valid values are START and END */ public SmartScroller(JScrollPane scrollPane, int scrollDirection, int viewportPosition) { if (scrollDirection != HORIZONTAL && scrollDirection != VERTICAL) throw new IllegalArgumentException("invalid scroll direction specified"); if (viewportPosition != START && viewportPosition != END) throw new IllegalArgumentException("invalid viewport position specified"); this.viewportPosition = viewportPosition; if (scrollDirection == HORIZONTAL) scrollBar = scrollPane.getHorizontalScrollBar(); else scrollBar = scrollPane.getVerticalScrollBar(); scrollBar.addAdjustmentListener(this); // Turn off automatic scrolling for text components Component view = scrollPane.getViewport().getView(); if (view instanceof JTextComponent) { JTextComponent textComponent = (JTextComponent) view; DefaultCaret caret = (DefaultCaret) textComponent.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } }
Example 3
Source File: HtmlPanel.java From jamel with GNU General Public License v3.0 | 5 votes |
/** * Initializes the specified {@code HtmlPanel}. * * @param htmlPanel * the {@code HtmlPanel} to be initialized. */ static private void init(HtmlPanel htmlPanel) { htmlPanel.jEditorPane = new JEditorPane(); htmlPanel.jEditorPane.setContentType("text/html"); htmlPanel.jEditorPane.setText(htmlPanel.htmlElement.getText()); htmlPanel.jEditorPane.setEditable(false); htmlPanel.jEditorPane.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) try { java.awt.Desktop.getDesktop().browse(e.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } }); htmlPanel.setPreferredSize(new Dimension(660, 400)); final Border border = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(ColorParser.getColor("background"), 5), BorderFactory.createLineBorder(Color.LIGHT_GRAY)); htmlPanel.setBorder(border); htmlPanel.setViewportView(htmlPanel.jEditorPane); // Smart scrolling final DefaultCaret caret = (DefaultCaret) htmlPanel.jEditorPane.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); htmlPanel.getVerticalScrollBar().addAdjustmentListener(htmlPanel); }
Example 4
Source File: SwingUtil.java From jlibs with Apache License 2.0 | 5 votes |
/** * sets text of textComp without moving its caret. * * @param textComp text component whose text needs to be set * @param text text to be set. null will be treated as empty string */ public static void setText(JTextComponent textComp, String text){ if(text==null) text = ""; if(textComp.getCaret() instanceof DefaultCaret){ DefaultCaret caret = (DefaultCaret)textComp.getCaret(); int updatePolicy = caret.getUpdatePolicy(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); try{ textComp.setText(text); }finally{ caret.setUpdatePolicy(updatePolicy); } }else{ int mark = textComp.getCaret().getMark(); int dot = textComp.getCaretPosition(); try{ textComp.setText(text); }finally{ int len = textComp.getDocument().getLength(); if(mark>len) mark = len; if(dot>len) dot = len; textComp.setCaretPosition(mark); if(dot!=mark) textComp.moveCaretPosition(dot); } } }
Example 5
Source File: SmartScroller.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Specify how the SmartScroller will function. * * @param scrollPane the scroll pane to monitor * @param scrollDirection indicates which JScrollBar to monitor. * Valid values are HORIZONTAL and VERTICAL. * @param viewportPosition indicates where the viewport will normally be * positioned as data is added. * Valid values are START and END */ public SmartScroller(JScrollPane scrollPane, int scrollDirection, int viewportPosition) { if (scrollDirection != HORIZONTAL && scrollDirection != VERTICAL) throw new IllegalArgumentException("invalid scroll direction specified"); if (viewportPosition != START && viewportPosition != END) throw new IllegalArgumentException("invalid viewport position specified"); this.viewportPosition = viewportPosition; if (scrollDirection == HORIZONTAL) scrollBar = scrollPane.getHorizontalScrollBar(); else scrollBar = scrollPane.getVerticalScrollBar(); scrollBar.addAdjustmentListener( this ); // Turn off automatic scrolling for text components Component view = scrollPane.getViewport().getView(); if (view instanceof JTextComponent) { JTextComponent textComponent = (JTextComponent)view; DefaultCaret caret = (DefaultCaret)textComponent.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } }
Example 6
Source File: PanelController.java From SproutLife with MIT License | 5 votes |
private void initStatsPanel() { getStatsPanel().getStatsTextPane().setContentType("text/html"); getStatsPanel().getStatsTextPane().setText(getGameModel().getStats().getDisplayText()); //Fixes scroll issues on setText(), we want to keep the scroll position where it is DefaultCaret caret = (DefaultCaret) getStatsPanel().getStatsTextPane().getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); }
Example 7
Source File: JScrollPane457.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void createAndShowGUI() { test = new JScrollPane457(); test.setBorder(new TitledBorder(new EtchedBorder(), "Text Area")); textArea = new JTextArea(25, 80); textArea.setEditable(false); for (int i = 0; i < NUMBER_OF_LINES; i++) { textArea.append("line " + i + " 1234567890qwertyuiopasdfghjklzxcvbnm 1234567890qwertyuiopasdfghjklzxcvbnm\n"); } JScrollPane scroll = new JScrollPane(textArea); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); test.add(scroll); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); frame = new JFrame("OGLTR_DisableGlyphModeState test"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(1000, 1000); frame.add(test); frame.pack(); frame.setVisible(true); }
Example 8
Source File: KernelStatusPanel.java From openAGV with Apache License 2.0 | 5 votes |
private void initComponents() { DefaultCaret caret = (DefaultCaret) statusTextArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); setAutoscrolls(true); setPreferredSize(new Dimension(183, 115)); statusTextArea.setEditable(false); statusTextArea.setColumns(20); statusTextArea.setFont(new Font("Monospaced", 0, 11)); // NOI18N statusTextArea.setLineWrap(true); statusTextArea.setRows(5); statusTextArea.setWrapStyleWord(true); setViewportView(statusTextArea); }
Example 9
Source File: CommitPanel.java From consulo with Apache License 2.0 | 5 votes |
DataPanel(@Nonnull Project project) { myProject = project; DefaultCaret caret = (DefaultCaret)getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); setBorder(JBUI.Borders.empty(0, ReferencesPanel.H_GAP, BOTTOM_BORDER, 0)); }
Example 10
Source File: LoggingPanel.java From ThingML-Tradfri with Apache License 2.0 | 5 votes |
private void jCheckBoxLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLogActionPerformed DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret(); if (jCheckBoxLog.isSelected()) { caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength()); jScrollPaneLog.setViewportView(jTextArea1); } else caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); }
Example 11
Source File: Editor.java From burp-flow with MIT License | 5 votes |
@Override public void setText(byte[] message) { caret = (DefaultCaret) editor.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); if (message != null) { editor.setText(helpers.bytesToString(message)); } caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); searchIndex = -1; }
Example 12
Source File: ControlCenterInfoHandler.java From openAGV with Apache License 2.0 | 5 votes |
/** * Displays the notification. * * @param notification The notification */ private void publish(UserNotification notification) { DefaultCaret caret = (DefaultCaret) textArea.getCaret(); if (autoScroll) { caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textArea.setCaretPosition(textArea.getDocument().getLength()); } else { caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } textArea.append(format(notification)); textArea.append("\n"); checkLength(); }
Example 13
Source File: ControlCenterInfoHandler.java From openAGV with Apache License 2.0 | 5 votes |
/** * Displays the notification. * * @param notification The notification */ private void publish(UserNotification notification) { DefaultCaret caret = (DefaultCaret) textArea.getCaret(); if (autoScroll) { caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textArea.setCaretPosition(textArea.getDocument().getLength()); } else { caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } textArea.append(format(notification)); textArea.append("\n"); checkLength(); }
Example 14
Source File: GUI.java From NanoJ-Fluidics with MIT License | 4 votes |
private Log() { super(); DefaultCaret caret = (DefaultCaret) this.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); }
Example 15
Source File: PrinterOutputImpl.java From escpos-printer-simulator with MIT License | 4 votes |
/** * Creates new form PrinterPanel */ public PrinterOutputImpl() { initComponents(); DefaultCaret caret = (DefaultCaret)txtDisplay.getCaret(); caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM); }
Example 16
Source File: ResultView.java From Raccoon with Apache License 2.0 | 4 votes |
/** * Construct a new app listing * * @param searchView * the searchview that will handle button presses. * * @param doc * the source from which to draw app info */ private ResultView(SearchView searchView, DocV2 doc) { this.doc = doc; this.searchView = searchView; model = new HashMap<String, Object>(); model.put("i18n_installs", Messages.getString("ResultView.1")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_rating", Messages.getString("ResultView.3")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_price", Messages.getString("ResultView.5")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_date", Messages.getString("ResultView.7")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_version", Messages.getString("ResultView.2")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_size", Messages.getString("ResultView.9")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_permissions", Messages.getString("ResultView.27")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_permissions_none", Messages.getString("ResultView.22")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("i18n_changelog", Messages.getString("ResultView.4")); //$NON-NLS-1$ //$NON-NLS-2$ model.put("title", doc.getTitle()); //$NON-NLS-1$ model.put("installs", doc.getDetails().getAppDetails().getNumDownloads()); //$NON-NLS-1$ model.put("rating", String.format("%.2f", doc.getAggregateRating().getStarRating())); //$NON-NLS-1$ //$NON-NLS-2$ model.put("package", doc.getBackendDocid()); //$NON-NLS-1$ model.put("author", doc.getCreator()); //$NON-NLS-1$ model.put("price", doc.getOffer(0).getFormattedAmount()); //$NON-NLS-1$ model.put("date", doc.getDetails().getAppDetails().getUploadDate()); //$NON-NLS-1$ model.put("size", Archive.humanReadableByteCount(doc.getDetails().getAppDetails() //$NON-NLS-1$ .getInstallationSize(), true)); File icon = SearchWorker.getImageCacheFile(doc.getBackendDocid(), 4); if (icon.exists()) { model.put("icon", icon.toURI()); //$NON-NLS-1$ } else { model.put("icon", getClass().getResource("/rsrc/icons/icon_missing.png").toString()); } JPanel buttons = new JPanel(); buttons.setLayout(new GridLayout(0, 1, 0, 4)); buttons.setOpaque(false); download = new JButton(Messages.getString("ResultView.25"), iconDownload); //$NON-NLS-1$ gplay = new JButton(Messages.getString("ResultView.26")); //$NON-NLS-1$ details = new JToggleButton(Messages.getString("ResultView.6")); //$NON-NLS-1$ permissions = new JToggleButton(Messages.getString("ResultView.27")); //$NON-NLS-1$ buttons.add(download); buttons.add(gplay); buttons.add(details); buttons.add(permissions); entry = new HypertextPane(TmplTool.transform("app.html", model)); //$NON-NLS-1$ entry.setMargin(new Insets(10, 10, 10, 10)); entry.addHyperlinkListener(new BrowseUtil()); // Keep enclosing scrollpanes steady DefaultCaret caret = (DefaultCaret) entry.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); JPanel outer = new JPanel(); // Needed to simplify the layout code. outer.setOpaque(false); JPanel container = new JPanel(); container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); container.setOpaque(false); container.add(buttons); container.add(Box.createVerticalStrut(10)); container.add(createBadges(doc.getDetails().getAppDetails().getPermissionList())); container.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); outer.add(container); JSeparator sep = new JSeparator(JSeparator.VERTICAL); sep.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(outer); add(sep); add(entry); }
Example 17
Source File: BasePanel.java From snowblossom with Apache License 2.0 | 4 votes |
public static void makeNotViewReset(JTextArea a) { DefaultCaret caret = (DefaultCaret) a.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); }
Example 18
Source File: OutputTopComponent.java From Open-LaTeX-Studio with MIT License | 4 votes |
@Override public void componentOpened() { DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); }
Example 19
Source File: TextPanel.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
protected void buildContent() { setLayout(new GridBagLayout()); this.inputTextPane = new JTextArea(); initKeyMap(this.inputTextPane); this.inputScrollPane = new JScrollPane(this.inputTextPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.outputTextPane = new JTextPane(); this.outputTextPane.setContentType("text/html"); HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); this.outputTextPane.setEditorKit(kit); this.outputTextPane.setDocument(doc); this.outputTextPane.setEditable(false); this.outputScrollPane = new JScrollPane(this.outputTextPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED ,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); DefaultCaret caret = (DefaultCaret) this.outputTextPane.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); this.submitButton = new JButton("Submit"); this.submitButton.addActionListener(new SubmitAction()); this.clearButton = new JButton("Clear"); this.clearButton.addActionListener(new ClearAction()); this.stateComboBox = new JComboBox(LanguageState.values()); this.stateComboBox.addActionListener(new StateChangedAction()); this.emotionComboBox = new JComboBox(EmotionalState.values()); this.emotionComboBox.addActionListener(new EmotionChangedAction()); this.correctionCheckBox = new JCheckBox("Correction"); this.offensiveCheckBox = new JCheckBox("Offensive"); this.avatarLabel = new JLabel(); add(this.outputScrollPane, new GridBagConstraints(0,0,1,10, 1.0,1.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.inputScrollPane, new GridBagConstraints(0,10,1,10, 1.0,0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,50)); add(this.submitButton, new GridBagConstraints(1,0,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.clearButton, new GridBagConstraints(1,1,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(new JLabel("Language state:"), new GridBagConstraints(1,2,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.stateComboBox, new GridBagConstraints(1,3,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(new JLabel("Emote:"), new GridBagConstraints(1,4,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.emotionComboBox, new GridBagConstraints(1,5,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.correctionCheckBox, new GridBagConstraints(1,6,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.offensiveCheckBox, new GridBagConstraints(1,7,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); add(this.avatarLabel, new GridBagConstraints(1,8,1,1, 0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(4,4,4,4), 0,0)); resetBotInstance(); }
Example 20
Source File: FocusDebugger.java From consulo with Apache License 2.0 | 3 votes |
private JComponent init() { final JPanel result = new JPanel(new BorderLayout()); myLogModel = new DefaultListModel(); myLog = new JBList(myLogModel); myLog.setCellRenderer(new FocusElementRenderer()); myAllocation = new JEditorPane(); final DefaultCaret caret = new DefaultCaret(); myAllocation.setCaret(caret); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); myAllocation.setEditable(false); final Splitter splitter = new Splitter(true); splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myLog)); splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myAllocation)); myLog.addListSelectionListener(this); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this); result.add(splitter, BorderLayout.CENTER); final DefaultActionGroup group = new DefaultActionGroup(); group.add(new ClearAction()); result.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH); return result; }