当前位置: 首页>>代码示例>>Java>>正文


Java JTextArea.getText方法代码示例

本文整理汇总了Java中javax.swing.JTextArea.getText方法的典型用法代码示例。如果您正苦于以下问题:Java JTextArea.getText方法的具体用法?Java JTextArea.getText怎么用?Java JTextArea.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.getText方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
     JTextArea area = TEdit.getTextArea();
     String txt = area.getText();
     if(txt == null)
         return;
     String s = TEdit.getLookingFor();
     if(s.contentEquals(""))
         return;
     if(txt.contentEquals("") || txt.length()<1)
         return;
      if(area.getCaretPosition() >=txt.length()-1){
          area.setCaretPosition(0);
          //JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
          //return;
      }
           int foundAt = txt.indexOf(s,area.getCaretPosition()+s.length());
           if(foundAt == -1){
               JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
               return;
           }
               area.setCaretPosition(foundAt);
               area.select(foundAt,foundAt+s.length());
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:25,代码来源:FindRight_Action.java

示例2: SetCursor

import javax.swing.JTextArea; //导入方法依赖的package包/类
public static int SetCursor(int newlineno,JTextArea textPane)
{
    int pos = 0;
    int i = 0;
    String line = "";
    Scanner scanner = new Scanner(textPane.getText());
    while (scanner.hasNextLine())
    {
        line = scanner.nextLine();
        i++;
        if (newlineno > i)
        {
            pos = pos + line.length() + 1;
        }
    }
    return pos;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:18,代码来源:BasicEvents.java

示例3: getFindInText

import javax.swing.JTextArea; //导入方法依赖的package包/类
/**
 * Returns the text in which to search, as a string.  This is used
 * internally to grab the smallest buffer possible in which to search.
 */
private static String getFindInText(JTextArea textArea, int start,
								boolean forward) {

	// Be smart about the text we grab to search in.  We grab more than
	// a single line because our searches can return multi-line results.
	// We copy only the chars that will be searched through.
	String findIn = null;
	try {
		if (forward) {
			findIn = textArea.getText(start,
						textArea.getDocument().getLength()-start);
		}
		else { // backward
			findIn = textArea.getText(0, start);
		}
	} catch (BadLocationException ble) {
		// Never happens; findIn will be null anyway.
		ble.printStackTrace();
	}

	return findIn;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:28,代码来源:SearchEngine.java

示例4: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
     JTextArea area = TEdit.getTextArea();
     String txt = area.getText();
     if(txt == null)
         return;
     String s = TEdit.getLookingFor();
     if(s.contentEquals(""))
         return;
     if(txt.contentEquals("") || txt.length()<1)
         return;
     if(area.getCaretPosition() < s.length()-1){
          JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
          return;
      }
           if(area.getCaretPosition()-s.length()<=0){
               area.setCaretPosition(txt.length()-1);
           }
           int foundAt = txt.substring(0,area.getCaretPosition()-s.length()).lastIndexOf(s);
           
           if(foundAt == -1){
               JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
               return;
           }
               area.setCaretPosition(foundAt);
               area.select(foundAt,foundAt+s.length());
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:28,代码来源:FindLeft_Action.java

示例5: createBlocksFromLines

import javax.swing.JTextArea; //导入方法依赖的package包/类
public void createBlocksFromLines() {

        final JTextArea textArea = new JTextArea();

        BaseDialog dialog = new BaseDialog(getPanel().getFramework()
                .getMainFrame()) {
            @Override
            protected void onOk() {
                if (textArea.getText().trim().length() > 0) {
                    StringTokenizer st = new StringTokenizer(
                            textArea.getText(), "\n");
                    List<String> strings = new ArrayList<String>();

                    while (st.hasMoreElements()) {
                        String s = st.nextToken().trim();
                        if (s.length() > 0)
                            strings.add(s);
                    }
                    startUserTransaction();
                    createBlocks(strings.toArray(new String[strings.size()]));
                    commitUserTransaction();
                    super.onOk();
                }
            }
        };

        dialog.setMainPane(new JScrollPane(textArea));

        ResourceLoader.setJComponentsText(dialog);

        dialog.setBounds(0, 0, 800, 600);
        dialog.setLocationRelativeTo(null);

        dialog.setVisible(true);
    }
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:36,代码来源:MovingArea.java

示例6: getLineCount

import javax.swing.JTextArea; //导入方法依赖的package包/类
public static int getLineCount(JTextArea textPane)
{
    _lineCount = 0;
    Scanner scanner = new Scanner(textPane.getText());
    while (scanner.hasNextLine())
    {
        String line = scanner.nextLine();
        _lineCount++;
    }
    return _lineCount;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:12,代码来源:BasicEvents.java

示例7: summaryAll

import javax.swing.JTextArea; //导入方法依赖的package包/类
public static void summaryAll() throws IOException{
    int sel = jTabbedPane1.getSelectedIndex();
    jLabel23.setText(jTabbedPane1.getTitleAt(sel));
    jLabel24.setText("File Location : " + titleText.getText());
    /**String[] {splitStrings = filesave.getSelectedFile().getName().split("\\.") ;
        String extension = splitStrings[splitStrings.length-1] ;
        fileext.setText(extension);}**/
    jLabel16.setText("File Extention : " + titleExtLa.getText());
    JTextArea textPane = (JTextArea) ((JScrollPane) ((JDesktopPane)jTabbedPane1.getComponentAt(sel)).getComponent(0)).getViewport().getComponent(0);
    String totaltext=  textPane.getText();
    String totalwords[]=totaltext.split("\\s");  
    jLabel21.setText("Total Word Typed : " + totalwords.length);
    jLabel5.setText("Total Characters With Spaces : " + totaltext.length());
    jLabel22.setText("Total Line : " + BasicEvents.getLineCount(textPane));
	if (titleText.getText().contains("Untitled")) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            DateFormat date = new SimpleDateFormat("dd/MM/yyyy");
            Calendar cal = Calendar.getInstance();
        jLabel27.setText(dateFormat.format(cal.getTime())); 
        jLabel25.setText(dateFormat.format(cal.getTime()));
    } else {
        Path filepath = Paths.get(titleText.getText()) ;
        BasicFileAttributes attr = Files.readAttributes(filepath, BasicFileAttributes.class);
            String dateCreate = ""+attr.creationTime() ; String dateCreat = dateCreate.replace("T", "  Time Created : ");
            String lastModi = ""+attr.lastModifiedTime() ; String lastMod = lastModi.replace("T", "  Last Time Modified : ");
             jLabel25.setText("Date Created : " + dateCreat );
            jLabel27.setText("Last Date Modified : " + lastMod );
    }
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:30,代码来源:summary.java

示例8: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesDesc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
开发者ID:fgulan,项目名称:java-course,代码行数:32,代码来源:SortLinesDescendingAction.java

示例9: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos;

        String text = currentEditor.getText(fromPos, length);
        text = sortLinesAsc(text);
        document.remove(fromPos, length);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(fromPos + length);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }

}
 
开发者ID:fgulan,项目名称:java-course,代码行数:32,代码来源:SortLinesAscendingAction.java

示例10: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document document = currentEditor.getDocument();
    Caret caret = currentEditor.getCaret();

    int startCaret = Math.min(caret.getDot(), caret.getMark());
    int endCaret = Math.max(caret.getDot(), caret.getMark());

    try {

        int startLine = currentEditor.getLineOfOffset(startCaret);
        int endLine = currentEditor.getLineOfOffset(endCaret);
        int fromPos = currentEditor.getLineStartOffset(startLine);
        int length = currentEditor.getLineEndOffset(endLine) - fromPos + 1;

        String text = currentEditor.getText(fromPos, length);
        text = removeLines(text);
        document.remove(fromPos, length - 1);
        document.insertString(fromPos, text, null);
        caret.setDot(fromPos);
        caret.moveDot(length - 1);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {
        observer.errorMessage(e1);
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:31,代码来源:UniqueLinesAction.java

示例11: getErrroLabelText

import javax.swing.JTextArea; //导入方法依赖的package包/类
private String getErrroLabelText(SelectorPanel sp) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    RepositorySelectorBuilder builder = (RepositorySelectorBuilder) getField(sp, "builder");
    RepositoryFormPanel form = (RepositoryFormPanel) getField(builder, "repositoryFormsPanel");
    JTextArea label = (JTextArea) getField(form, "errorText");
    return label.getText();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:RepositorySelectorTest.java

示例12: actionPerformed

import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    JTextArea area = TEdit.getTextArea();
    if(area.getText().length()==0){
        JOptionPane.showMessageDialog(TEdit.getFrame(),"There is nothing to replace!");
        return;
    }
    JTextField source = new JTextField();
    JTextField target = new JTextField();
    Object[] message = {
                          "Source:", source,
                          "Target:", target
                        };
    int option = JOptionPane.showConfirmDialog(TEdit.getFrame(), message, "Replace", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE,myIcon);
    if (option != JOptionPane.OK_OPTION)
        return;
    
    String src = source.getText();
    String trgt= target.getText();
    
    if(src.contentEquals(""))
            return;
    
             Highlighter hilite = area.getHighlighter();
     Highlighter.Highlight[] hilites = hilite.getHighlights();
     int Shift=0;
     String txt=area.getText();
     if(hilites != null && hilites.length >0){ 
         for (Highlighter.Highlight hilite1 : hilites) {
                //txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()))
               area.replaceRange(txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()).replace(src,trgt),
                              hilite1.getStartOffset()-Shift, hilite1.getEndOffset()-Shift);
               Shift = Shift -(src.length()-trgt.length());
         }
        
     }
     else{
         txt=txt.replace(src,trgt);
         area.setText(txt);
     }
            
            
    
     
}
 
开发者ID:mathhobbit,项目名称:EditCalculateAndChart,代码行数:46,代码来源:Replace_Action.java

示例13: start

import javax.swing.JTextArea; //导入方法依赖的package包/类
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:63,代码来源:WrongKeyTypedConsumedTest.java

示例14: sessionUI

import javax.swing.JTextArea; //导入方法依赖的package包/类
protected void sessionUI() {
	setSessionID();
	//textfields needed for UI
	JTextField sessionIDText = new JTextField(getSessionID());
	sessionIDText.setEditable(false);
	JTextArea sessionDescripText = new JTextArea(4,5);
	sessionDescripText.setLineWrap(true);
	JScrollPane scrollPane = new JScrollPane(sessionDescripText);
       
	//Radio Button List
	JRadioButton newFeature = new JRadioButton("New Feature");
	JRadioButton bugFix = new JRadioButton("Bug Fix");
	JRadioButton refactoring = new JRadioButton("Refactoring");
	JRadioButton genComp = new JRadioButton("General Comprehension");
	JRadioButton other = new JRadioButton("Other");
	
	//Group the buttons
	ButtonGroup radioList = new ButtonGroup();
	radioList.add(newFeature);
	radioList.add(bugFix);
	radioList.add(refactoring);
	radioList.add(genComp);
	radioList.add(other);
	
	//Add to a JPanel
	JPanel radioPanel = new JPanel(new GridLayout(0, 1));
	radioPanel.add(newFeature);
	radioPanel.add(bugFix);
	radioPanel.add(refactoring);
	radioPanel.add(genComp);
	radioPanel.add(other);
	
	//Add everything to main JPanel
	JPanel sessionPanel = new JPanel(); //main panel
	sessionPanel.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.NONE;
	c.anchor = GridBagConstraints.NORTHWEST;
	
	c.gridx = 0;
	c.gridy = 0;
	sessionPanel.add(new JLabel("Generated Session ID:"),c);
	c.gridx++;
	sessionPanel.add(sessionIDText,c);
	c.gridx = 0;
	c.gridy++;
	sessionPanel.add(new JLabel("Session Purpose (select one):"),c);
	c.gridx++;
	sessionPanel.add(radioPanel,c);
	c.gridx = 0;
	c.gridy++;
	sessionPanel.add(new JLabel("Enter the Session Description:"),c);
	c.gridx++;
	c.fill = GridBagConstraints.HORIZONTAL;
	sessionPanel.add(scrollPane,c);
	
	final int selection = JOptionPane.showConfirmDialog(null, sessionPanel, 
			"Enter the Current Session Info.",
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
	if (selection == JOptionPane.OK_OPTION) {
		sessionDescrip = sessionDescripText.getText();
		if (newFeature.isSelected()) {
			sessionPurpose = newFeature.getText();
		} else if (bugFix.isSelected()) {
			sessionPurpose = bugFix.getText();
		} else if (refactoring.isSelected()) {
			sessionPurpose = refactoring.getText();
		} else if (genComp.isSelected()) {
			sessionPurpose = genComp.getText();
		} else if (other.isSelected()) {
			sessionPurpose = other.getText();
		} else {
			sessionPurpose = new String();
			System.out.println("Warning! "
					+ "Your Session Purpose has not been selected.");
		}
		hasSessionInfo = true;
	}  
}
 
开发者ID:SERESLab,项目名称:iTrace-Archive,代码行数:80,代码来源:SessionInfoHandler.java


注:本文中的javax.swing.JTextArea.getText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。