javax.swing.text.DefaultCaret#setUpdatePolicy ( )源码实例Demo

下面列出了javax.swing.text.DefaultCaret#setUpdatePolicy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: workcraft   文件: LogPanel.java
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();
}
 
源代码2 项目: openAGV   文件: KernelStatusPanel.java
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);
}
 
源代码3 项目: openAGV   文件: ControlCenterInfoHandler.java
/**
 * 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();
}
 
源代码4 项目: openAGV   文件: ControlCenterInfoHandler.java
/**
 * 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();
}
 
源代码5 项目: burp-flow   文件: Editor.java
@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;
}
 
源代码6 项目: ThingML-Tradfri   文件: LoggingPanel.java
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);
    
}
 
源代码7 项目: consulo   文件: CommitPanel.java
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));
}
 
源代码8 项目: 07kit   文件: SmartScroller.java
/**
 * 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);
    }
}
 
源代码9 项目: jdk8u_jdk   文件: JScrollPane457.java
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);
}
 
源代码10 项目: SproutLife   文件: PanelController.java
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);
}
 
源代码11 项目: mars-sim   文件: SmartScroller.java
/**
 *  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);
	}
}
 
源代码12 项目: jlibs   文件: SwingUtil.java
/**
 * 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);
        }
    }
}
 
源代码13 项目: jamel   文件: HtmlPanel.java
/**
 * 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);

}
 
源代码14 项目: Open-LaTeX-Studio   文件: OutputTopComponent.java
@Override
public void componentOpened() {
    DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
}
 
源代码15 项目: snowblossom   文件: BasePanel.java
public static void makeNotViewReset(JTextArea a)
{
  DefaultCaret caret = (DefaultCaret) a.getCaret();
  caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
 
源代码16 项目: Raccoon   文件: ResultView.java
/**
 * 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);
}
 
源代码17 项目: NanoJ-Fluidics   文件: GUI.java
private Log() {
    super();
    DefaultCaret caret = (DefaultCaret) this.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
}
 
/**
 * Creates new form PrinterPanel
 */
public PrinterOutputImpl() {
    initComponents();
    DefaultCaret caret = (DefaultCaret)txtDisplay.getCaret();
    caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM);
}
 
源代码19 项目: BotLibre   文件: TextPanel.java
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();		
}
 
源代码20 项目: consulo   文件: FocusDebugger.java
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;
}