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

The following examples show how to use javax.swing.JTextArea#getText() . 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: CustomNamesEditorDialog.java    From universal-pokemon-randomizer with GNU General Public License v3.0 6 votes vote down vote up
private List<String> getNameList(JTextArea textArea) {
    String contents = textArea.getText();
    // standardize newlines
    contents = contents.replace("\r\n", "\n");
    contents = contents.replace("\r", "\n");
    // split by them
    String[] names = contents.split("\n");
    List<String> results = new ArrayList<String>();
    for (String name : names) {
        String ln = name.trim();
        if (!ln.isEmpty()) {
            results.add(ln);
        }
    }
    return results;
}
 
Example 2
Source File: GUI.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Browse file.
 *
 * @param f the f
 */
void browseFile(JTextArea f) {
  String startingDir = f.getText();
  if (startingDir.length() == 0) {
    // default to user.dir
    startingDir = System.getProperty("user.dir");
  }
  JFileChooser c = new JFileChooser(startingDir);
  int returnVal = c.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    try {
      f.setText(c.getSelectedFile().getCanonicalPath());
      Prefs.set(gui);
    } catch (Exception e) { // do nothing
    }
  }
}
 
Example 3
Source File: GUI.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Browse dir.
 *
 * @param f the f
 */
void browseDir(JTextArea f) {
  String startingDir = f.getText();
  if (startingDir.length() == 0) {
    // default to user.dir
    startingDir = System.getProperty("user.dir");
  }
  JFileChooser c = new JFileChooser(startingDir);
  c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  int returnVal = c.showOpenDialog(gui);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    try {
      f.setText(c.getSelectedFile().getCanonicalPath());
      Prefs.set(gui);
    } catch (Exception e) { // do nothing
    }
  }
}
 
Example 4
Source File: PanelLogging.java    From java-ocr-api with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void logAndScrollToBottom(final JTextArea textArea, final String mesg) {
    if(! SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                logAndScrollToBottom(textArea, mesg);
            }
        });
        return;
    }
    textArea.append(textArea.getText().length() == 0 ? mesg : "\n" + mesg);

    String text = textArea.getText();
    if(text.length() > 2) {
        int lastLinePos = text.lastIndexOf("\n", text.length() - 2);
        if(lastLinePos > 0) {
            textArea.setCaretPosition(lastLinePos + 1); 
        }
    }
}
 
Example 5
Source File: CodeDialog.java    From stone with MIT License 5 votes vote down vote up
protected String showDialog() {
    JTextArea area = new JTextArea(20, 40);
    JScrollPane pane = new JScrollPane(area);
    int result = JOptionPane.showOptionDialog(null, pane, "Input",
                                              JOptionPane.OK_CANCEL_OPTION,
                                              JOptionPane.PLAIN_MESSAGE,
                                              null, null, null);
    if (result == JOptionPane.OK_OPTION)
        return area.getText();
    else
        return null;
}
 
Example 6
Source File: DesignerTablePanel.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
            String expression = expressionColumn.getName();
//            String result = (String) JOptionPane.showInputDialog(Globals.getMainFrame(), null, "Expression",
//                    JOptionPane.QUESTION_MESSAGE, null, null, expression);

            final JTextArea textArea = new JTextArea(expression, 10, 30);
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setEditable(true);

            Object msg[] = {"", new JScrollPane(textArea)};
//
            int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                    msg, I18NSupport.getString("designer.expression"),
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

            if (option == JOptionPane.YES_OPTION) {
                String result = textArea.getText();
                if (expressionColumn instanceof ExpressionColumn) {
                    ((ExpressionColumn) expressionColumn).setExpression(result);
                } else if (expressionColumn instanceof GroupByFunctionColumn) {
                    ((GroupByFunctionColumn) expressionColumn).setExpression(result);
                }
                okPressed = true;
            }

            table.packAll();
        }
 
Example 7
Source File: NamedQueryPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public static String showDescription(Component component, String title, String description) {
    JTextArea descriptionArea = new JTextArea(15, 50);
    descriptionArea.setText(description);
    JScrollPane scrollPane = new JScrollPane(descriptionArea);
    if(JOptionPane.showConfirmDialog(component, scrollPane, title, OK_CANCEL_OPTION) == OK_OPTION) {
        return descriptionArea.getText();
    }
    return description;
}
 
Example 8
Source File: WrongKeyTypedConsumedTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 9
Source File: InsertWktGeometryAction.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    JTextArea textArea = new JTextArea(16, 32);
    textArea.setEditable(true);

    JPanel contentPanel = new JPanel(new BorderLayout(4, 4));
    contentPanel.add(new JLabel("Geometry Well-Known-Text (WKT):"), BorderLayout.NORTH);
    contentPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);

    SnapApp snapApp = SnapApp.getDefault();
    ModalDialog modalDialog = new ModalDialog(snapApp.getMainFrame(),
                                              Bundle.CTL_InsertWktGeometryAction_DialogTitle(),
                                              ModalDialog.ID_OK_CANCEL, null);
    modalDialog.setContent(contentPanel);
    modalDialog.center();
    if (modalDialog.show() == ModalDialog.ID_OK) {
        String wellKnownText = textArea.getText();
        if (wellKnownText == null || wellKnownText.isEmpty()) {
            return;
        }
        ProductSceneView sceneView = snapApp.getSelectedProductSceneView();
        VectorDataLayer vectorDataLayer = InsertFigureInteractorInterceptor.getActiveVectorDataLayer(sceneView);
        if (vectorDataLayer == null) {
            return;
        }

        SimpleFeatureType wktFeatureType = PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84);
        ListFeatureCollection newCollection = new ListFeatureCollection(wktFeatureType);
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(wktFeatureType);
        SimpleFeature wktFeature = featureBuilder.buildFeature("ID" + Long.toHexString(currentFeatureId++));
        Geometry geometry;
        try {
            geometry = new WKTReader().read(wellKnownText);
        } catch (ParseException e) {
            snapApp.handleError("Failed to convert WKT into geometry", e);
            return;
        }
        wktFeature.setDefaultGeometry(geometry);
        newCollection.add(wktFeature);

        FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds(
                newCollection,
                sceneView.getProduct(),
                null,
                ProgressMonitor.NULL);
        if (productFeatures.isEmpty()) {
            Dialogs.showError(Bundle.CTL_InsertWktGeometryAction_MenuText(),
                              "The geometry is not contained in the product.");
        } else {
            vectorDataLayer.getVectorDataNode().getFeatureCollection().addAll(productFeatures);
        }
    }
}
 
Example 10
Source File: WrongKeyTypedConsumedTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 11
Source File: WrongKeyTypedConsumedTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 12
Source File: WrongKeyTypedConsumedTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 13
Source File: WrongKeyTypedConsumedTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 14
Source File: WrongKeyTypedConsumedTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 15
Source File: WrongKeyTypedConsumedTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 16
Source File: WrongKeyTypedConsumedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 17
Source File: RepositorySelectorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 18
Source File: WrongKeyTypedConsumedTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 19
Source File: WrongKeyTypedConsumedTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 20
Source File: WrongKeyTypedConsumedTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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");
}