javax.swing.text.DefaultCaret Java Examples

The following examples show how to use javax.swing.text.DefaultCaret. 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: AbstractCodeArea.java    From jadx with Apache License 2.0 6 votes vote down vote up
public AbstractCodeArea(ContentPanel contentPanel) {
	this.contentPanel = contentPanel;
	this.node = contentPanel.getNode();

	setMarkOccurrences(true);
	setEditable(false);
	setCodeFoldingEnabled(false);
	loadSettings();

	Caret caret = getCaret();
	if (caret instanceof DefaultCaret) {
		((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
	}
	caret.setVisible(true);

	registerWordHighlighter();
}
 
Example #2
Source File: SwingTextAreaWrapper.java    From kafka-message-tool with MIT License 6 votes vote down vote up
public SwingTextAreaWrapper(JTextArea textArea) {
    this.textArea = textArea;
    textArea.setEditable(true);
    textArea.setFont(FONT);

    final DefaultCaret caret = (DefaultCaret) textArea.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    node = new SwingNode();
    JScrollPane sp = new JScrollPane(textArea);
    textArea.setComponentPopupMenu(popupMenu);
    node.setContent(sp);

    popupMenu.add(saveToFileMenu);

}
 
Example #3
Source File: LogPanel.java    From workcraft with MIT License 6 votes vote down vote up
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 #4
Source File: MaterialPasswordField.java    From swing-material with MIT License 6 votes vote down vote up
/**
 * Creates a new password field.
 */
public MaterialPasswordField() {
    setBorder(null);
    setFont(getFont().deriveFont(16f)); //use default font, Roboto's bullet doesn't work on some platforms (i.e. Mac)
    floatingLabel.setText("");
    setOpaque(false);
    setBackground(MaterialColor.TRANSPARENT);

    setCaret(new DefaultCaret() {
        @Override
        protected synchronized void damage(Rectangle r) {
            MaterialPasswordField.this.repaint(); //fix caret not being removed completely
        }
    });
    getCaret().setBlinkRate(500);
}
 
Example #5
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void updateUI() {
  super.updateUI();
  setOpaque(false);
  Caret caret = new DefaultCaret() {
    // [UnsynchronizedOverridesSynchronized]
    // Unsynchronized method damage overrides synchronized method in DefaultCaret
    @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
    @Override protected synchronized void damage(Rectangle r) {
      if (Objects.nonNull(r)) {
        JTextComponent c = getComponent();
        x = 0;
        y = r.y;
        width = c.getSize().width;
        height = r.height;
        c.repaint();
      }
    }
  };
  // caret.setBlinkRate(getCaret().getBlinkRate());
  caret.setBlinkRate(UIManager.getInt("TextArea.caretBlinkRate"));
  setCaret(caret);
}
 
Example #6
Source File: FrmTextEditor.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates new form FrmTextEditor
 */
public FrmTextEditor() {
    initComponents();

    DefaultCaret caret = (DefaultCaret) this.jTextArea_Output.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    BufferedImage image = null;
    try {
        image = ImageIO.read(this.getClass().getResource("/images/snake.png"));
        this.setIconImage(image);
    } catch (Exception e) {
    }
    this.setScriptLanguage(_scriptLanguage);
    addNewTextEditor("New file");
    this._splitPanelSize = this.jSplitPane1.getBounds().getSize();
    this.setSize(600, 600);
    //this.jSplitPane1.setDividerLocation(0.6);
    this.jSplitPane1.setDividerLocation(5);
    //this.jScrollPane1.invalidate();
}
 
Example #7
Source File: SwingUtilities2.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the {@code SKIP_CLICK_COUNT} client property on the component
 * if it is an instance of {@code JTextComponent} with a
 * {@code DefaultCaret}. This property, used for text components acting
 * as editors in a table or tree, tells {@code DefaultCaret} how many
 * clicks to skip before starting selection.
 */
public static void setSkipClickCount(Component comp, int count) {
    if (comp instanceof JTextComponent
            && ((JTextComponent) comp).getCaret() instanceof DefaultCaret) {

        ((JTextComponent) comp).putClientProperty(SKIP_CLICK_COUNT, count);
    }
}
 
Example #8
Source File: bug7083457.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();

    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
 
Example #9
Source File: bug6938583.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JTextArea jta = new JTextArea();
            DefaultCaret dc = new DefaultCaret();
            jta.setCaret(dc);
            dc.deinstall(jta);
            dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 0, false));
        }
    });
}
 
Example #10
Source File: LogPanel.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public LogPanel(Translator translator, RobotEntity robot) {
	this.translator = translator;
	this.robot = robot;
	
	// log panel
	Log.addListener(this);

	// the log panel
	log = new JTextPane();
	log.setEditable(false);
	log.setBackground(Color.BLACK);
	kit = new HTMLEditorKit();
	doc = new HTMLDocument();
	log.setEditorKit(kit);
	log.setDocument(doc);
	DefaultCaret caret = (DefaultCaret) log.getCaret();
	caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

	JScrollPane logPane = new JScrollPane(log);

	// Now put all the parts together
	panel.setLayout(new GridBagLayout());
	GridBagConstraints con1 = new GridBagConstraints();
	con1.gridx = 0;
	con1.gridy = 0;
	con1.weightx=1;
	con1.weighty=1;
	con1.fill=GridBagConstraints.HORIZONTAL;
	con1.anchor=GridBagConstraints.NORTHWEST;
	panel.add(logPane,con1);
	con1.gridy++;


	con1.weightx=1;
	con1.weighty=0;
	panel.add(getTextInputField(),con1);
	
	// lastly, clear the log
	clearLog();
}
 
Example #11
Source File: SwingUtilities2.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the {@code SKIP_CLICK_COUNT} client property on the component
 * if it is an instance of {@code JTextComponent} with a
 * {@code DefaultCaret}. This property, used for text components acting
 * as editors in a table or tree, tells {@code DefaultCaret} how many
 * clicks to skip before starting selection.
 */
public static void setSkipClickCount(Component comp, int count) {
    if (comp instanceof JTextComponent
            && ((JTextComponent) comp).getCaret() instanceof DefaultCaret) {

        ((JTextComponent) comp).putClientProperty(SKIP_CLICK_COUNT, count);
    }
}
 
Example #12
Source File: bug6938583.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JTextArea jta = new JTextArea();
            DefaultCaret dc = new DefaultCaret();
            jta.setCaret(dc);
            dc.deinstall(jta);
            dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 0, false));
        }
    });
}
 
Example #13
Source File: ResultSetTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ResultSetTableCellEditor(final JTextField textField) {
    super(textField);
    delegate = new EditorDelegate() {

        @Override
        public void setValue(Object value) {
            val = value;
            textField.setText((value != null) ? value.toString() : "");
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            String txtVal = textField.getText();
            if (val == null && txtVal.equals("")) {
                return null;
            } else {
                    return txtVal;
                }
            }
    };

    textField.addActionListener(delegate);
    // #204176 - workarround for MacOS L&F
    textField.setCaret(new DefaultCaret());
}
 
Example #14
Source File: bug7083457.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();

    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
 
Example #15
Source File: SmartScroller.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  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 #16
Source File: PanelController.java    From SproutLife with MIT License 5 votes vote down vote up
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 #17
Source File: bug6938583.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JTextArea jta = new JTextArea();
            DefaultCaret dc = new DefaultCaret();
            jta.setCaret(dc);
            dc.deinstall(jta);
            dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 0, false));
        }
    });
}
 
Example #18
Source File: bug7083457.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();

    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
 
Example #19
Source File: RTDebuggerWindow.java    From trygve with GNU General Public License v2.0 5 votes vote down vote up
@Override public int getSelectionEnd() {
 final Caret caret = super.getCaret();
 if (null == caret) {
  setCaret(new DefaultCaret());
 }
 final int end = null == caret? 0: Math.max(caret.getDot(), caret.getMark());
 return end;
}
 
Example #20
Source File: SmartScroller.java    From 07kit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #21
Source File: ShellTextComponent.java    From basicv2 with The Unlicense 5 votes vote down vote up
public ShellTextComponent(BasicShell sf) {
	parent = sf;
	setBackground(new Color(Colors.COLORS[6]));
	setDoubleBuffered(true);
	setForeground(new Color(Colors.COLORS[14]));
	setCaretColor(new Color(Colors.COLORS[14]));
	setToolTipText("<html>Type one of:<br>" + "- cls<br>- list<br>- run<br>- new<br>"
			+ "- save[file]<br>- load[file]<br>- compile[file]<br>- dir<br>"
			+ "or edit your BASIC code here</html>");
	BlockCaret mc = new BlockCaret();
	mc.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
	setCaret(mc);
	setFont(ResourceLoader.getFont());
	new DropTarget(this, new DropTargetAdapter() {
		@Override
		public void drop(DropTargetDropEvent event) {
			event.acceptDrop(DnDConstants.ACTION_COPY);
			Transferable transferable = event.getTransferable();
			DataFlavor[] flavors = transferable.getTransferDataFlavors();
			for (DataFlavor flavor : flavors) {
				try {
					if (flavor.isFlavorJavaFileListType()) {
						@SuppressWarnings("unchecked")
						List<File> files = (List<File>) transferable.getTransferData(flavor);
						File f = files.get(0);
						parent.getStore().load(f.getPath());
						parent.putStringUCase("Loaded: " + f.getName() + "\n" + ProgramStore.OK);
						return; // only one file
					}
				} catch (Exception e) {
					parent.putString(ProgramStore.ERROR);
				}
			}
		}
	});
}
 
Example #22
Source File: bug6938583.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JTextArea jta = new JTextArea();
            DefaultCaret dc = new DefaultCaret();
            jta.setCaret(dc);
            dc.deinstall(jta);
            dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 0, false));
        }
    });
}
 
Example #23
Source File: SwingUtilities2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the {@code SKIP_CLICK_COUNT} client property on the component
 * if it is an instance of {@code JTextComponent} with a
 * {@code DefaultCaret}. This property, used for text components acting
 * as editors in a table or tree, tells {@code DefaultCaret} how many
 * clicks to skip before starting selection.
 */
public static void setSkipClickCount(Component comp, int count) {
    if (comp instanceof JTextComponent
            && ((JTextComponent) comp).getCaret() instanceof DefaultCaret) {

        ((JTextComponent) comp).putClientProperty(SKIP_CLICK_COUNT, count);
    }
}
 
Example #24
Source File: KernelStatusPanel.java    From openAGV with Apache License 2.0 5 votes vote down vote up
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 #25
Source File: bug7083457.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();

    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
 
Example #26
Source File: bug6938583.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JTextArea jta = new JTextArea();
            DefaultCaret dc = new DefaultCaret();
            jta.setCaret(dc);
            dc.deinstall(jta);
            dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 0, false));
        }
    });
}
 
Example #27
Source File: RTDebuggerWindow.java    From trygve with GNU General Public License v2.0 5 votes vote down vote up
@Override public int getSelectionStart() {
 final Caret caret = super.getCaret();
 if (null == caret) {
  setCaret(new DefaultCaret());
 }
 final int start = null == caret? 0: Math.min(caret.getDot(), caret.getMark());
 return start;
}
 
Example #28
Source File: SwingUtilities2.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the {@code SKIP_CLICK_COUNT} client property on the component
 * if it is an instance of {@code JTextComponent} with a
 * {@code DefaultCaret}. This property, used for text components acting
 * as editors in a table or tree, tells {@code DefaultCaret} how many
 * clicks to skip before starting selection.
 */
public static void setSkipClickCount(Component comp, int count) {
    if (comp instanceof JTextComponent
            && ((JTextComponent) comp).getCaret() instanceof DefaultCaret) {

        ((JTextComponent) comp).putClientProperty(SKIP_CLICK_COUNT, count);
    }
}
 
Example #29
Source File: bug7083457.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();

    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
 
Example #30
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@code SKIP_CLICK_COUNT} client property on the component
 * if it is an instance of {@code JTextComponent} with a
 * {@code DefaultCaret}. This property, used for text components acting
 * as editors in a table or tree, tells {@code DefaultCaret} how many
 * clicks to skip before starting selection.
 */
public static void setSkipClickCount(Component comp, int count) {
    if (comp instanceof JTextComponent
            && ((JTextComponent) comp).getCaret() instanceof DefaultCaret) {

        ((JTextComponent) comp).putClientProperty(SKIP_CLICK_COUNT, count);
    }
}