Java Code Examples for javax.swing.JTextArea#getCaret()

The following examples show how to use javax.swing.JTextArea#getCaret() . 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: ChatMainPane.java    From osrsclient with GNU General Public License v2.0 6 votes vote down vote up
public void addChanPanel(String chanName) {

        JTextArea messagePanel = new JTextArea();
        messagePanel.setLineWrap(true);
        messagePanel.setBackground(new Color(71, 71, 71));
        messagePanel.setForeground(Color.white);
        messagePanel.setFont(ircFont);
        messagePanel.setEditable(false);
        DefaultCaret dc = (DefaultCaret) messagePanel.getCaret();
        dc.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

        JTextArea userPanel = new JTextArea();
        userPanel.setBackground(new Color(71, 71, 71));

        messagePanels.put(chanName, messagePanel);
        userPanels.put(chanName, userPanel);
       
    }
 
Example 2
Source File: Console.java    From AML-Project with Apache License 2.0 6 votes vote down vote up
public Console()
{
	super();
	this.setTitle("Console");
	this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
	this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
	console = new JTextArea(25,50);
	console.setEditable(false);
	out = new ConsoleOutputStream(console);
	stdout = System.out;
	stderr = System.err;
      	System.setOut(new PrintStream(out, true));
      	System.setErr(new PrintStream(out, true));
       JScrollPane scroll = new JScrollPane(console,
       		JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
               JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
       DefaultCaret caret = (DefaultCaret)console.getCaret();
       caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
       add(scroll);
       setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
       
       this.pack();
	GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
	int left = g.getCenterPoint().x - (int)(this.getPreferredSize().width / 2);
	this.setLocation(left, 0);
   }
 
Example 3
Source File: ConsoleTab.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public ConsoleTab()
{
	this.setLayout(_layout);
	_cons.fill = GridBagConstraints.BOTH;
	_cons.weightx = 1;
	_cons.weighty = 1;
	_cons.insets = new Insets(5,5,5,5);
	_textPane = new JTextArea();
	_textPane.setEditable(false);
	DefaultCaret caret = (DefaultCaret)_textPane.getCaret();
	caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
	this.add(new JScrollPane(_textPane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),_cons);
}
 
Example 4
Source File: CslTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void assertAutoQuery(QueryType queryType, String source, String typedText) {
    CodeCompletionHandler completer = getCodeCompleter();
    int caretPos = source.indexOf('^');
    source = source.substring(0, caretPos) + source.substring(caretPos+1);

    BaseDocument doc = getDocument(source);
    JTextArea ta = new JTextArea(doc);
    Caret caret = ta.getCaret();
    caret.setDot(caretPos);

    QueryType qt = completer.getAutoQuery(ta, typedText);
    assertEquals(queryType, qt);
}
 
Example 5
Source File: JScrollPane457.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 6
Source File: BasePanel.java    From snowblossom with Apache License 2.0 4 votes vote down vote up
public static void makeNotViewReset(JTextArea a)
{
  DefaultCaret caret = (DefaultCaret) a.getCaret();
  caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
 
Example 7
Source File: SyncSinkFrame.java    From Panako with GNU Affero General Public License v3.0 4 votes vote down vote up
public SyncSinkFrame(){
	super("SyncSink");
	
	logTextField = new JTextArea();
	logTextField.setEditable(false);
	DefaultCaret caret = (DefaultCaret)logTextField.getCaret();
	caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
	
	StringBuilder sb = new StringBuilder();
	sb.append("----------------------------------------\n");
	sb.append("Configuration currently in use: \n");
	for(Key key : Key.values()){
		sb.append("\t");
		sb.append(key.name());
		sb.append("=");
		sb.append(Config.get(key));
		sb.append("\n");
	}
	sb.append("----------------------------------------\n");
	logTextField.setText(sb.toString());
	
	
	this.setLayout(new BorderLayout());
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	cs = new CoordinateSystem(AxisUnit.OCCURENCES, 0, 1000);
	
	linkedPanel = new LinkedPanel(cs);
	linkedPanel.addLayer(new BackgroundLayer(cs));
	linkedPanel.addLayer(new ZoomMouseListenerLayer());
	linkedPanel.addLayer(new DragMouseListenerLayer(cs));
	linkedPanel.addLayer(new BackgroundLayer(cs));
	linkedPanel.addLayer(new TimeAxisLayer(cs));
	linkedPanel.addLayer(new SelectionLayer(cs));
	linkedPanel.getViewPort().addViewPortChangedListener(this);
	
	matches = new ArrayList<NFFTSyncMatch>();
	
	this.streamLayers = new ArrayList<StreamLayer>();
	this.streamFiles = new ArrayList<File>();
	
	JTabbedPane tabbedPane = new JTabbedPane();

	
	tabbedPane.addTab("Timebox plot", null, linkedPanel,"Timebox plots");
	tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

	
	tabbedPane.addTab("Messages", null, new JScrollPane(logTextField),"Logs messages");
	tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
	
	tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
	tabbedPane.setBorder(new EmptyBorder(0,0,0,0));
	
	this.add(tabbedPane,BorderLayout.CENTER);
	this.add(createStatusBarPanel(),BorderLayout.SOUTH);
	
	new FileDrop(null, tabbedPane, /*dragBorder,*/ new FileDrop.Listener(){   
		public void filesDropped( final File[] files ){  
			new Thread(new Runnable(){
				@Override
				public void run() {
					for( int i = 0; i < files.length; i++) {   
						final File fileToAdd = files[i];
						logMessage("Adding " + fileToAdd.getPath()  + "...");							
			            openFile(fileToAdd,streamFiles.size());
			            logMessage("Added " + fileToAdd.getPath()  + ".");	
	                }
			}},"File adding thread").start();
		}
       });
}