Java Code Examples for java.awt.TextArea#setText()

The following examples show how to use java.awt.TextArea#setText() . 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: TextAreaScrolling.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
TextAreaScrolling() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException("Robot Creation Failed");
    }

    mainFrame = new Frame();
    mainFrame.setSize(200, 200);
    mainFrame.setLocation(200, 200);

    textArea = new TextArea();
    textArea.setText("1234 5678");
    textArea.setSelectionStart(3);
    textArea.setSelectionEnd(4);
    mainFrame.add(textArea);
    mainFrame.setVisible(true);
    textArea.requestFocusInWindow();
}
 
Example 2
Source File: SelectionVisible.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    tf = new TextArea(3, 20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 012345 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 3
Source File: SelectionVisible.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    tf = new TextArea(3, 20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 012345 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 4
Source File: SelectionVisible.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 5
Source File: SelectionVisible.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 6
Source File: SelectionVisible.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 7
Source File: OverScrollTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textArea = new TextArea(2, 10);
    textArea.setSize(300, 100);
    textArea.setText("123456 789123");
    mainFrame.add(textArea);
    mainFrame.setVisible(true);
    textArea.requestFocusInWindow();
}
 
Example 8
Source File: SelectionVisible.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 9
Source File: SelectionVisible.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 10
Source File: SelectionVisible.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 11
Source File: SelectionVisible.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 12
Source File: SelectionVisible.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 13
Source File: SelectionVisible.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 14
Source File: SelectionVisible.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    ta = new TextArea(4, 20);
    ta.setText("01234\n56789");
    ta.select(3, 9);

    final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 34567 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    instruction.setEditable(false);
    instruction.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(ta);
    setLayout(new BorderLayout());
    add(instruction, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
Example 15
Source File: GIPApplet.java    From swift-k with Apache License 2.0 5 votes vote down vote up
public EmailConfirmationDialog(Frame parent, String[] messages, String textArea) {

        super(parent, true);
        setTitle("Confirmation Dialog");

        Font font = new Font("Courier", Font.PLAIN, 12);
        setFont(font);
        
        int rows = messages.length;
        Panel textPanel = new Panel();
        textPanel.setLayout(new GridLayout(rows,1));
        for(int i = 0; i < rows; i++){
            textPanel.add(new Label(messages[i]));
        }
        add("North", textPanel);

        Panel textAreaPanel = new Panel();
        TextArea ta = new TextArea(12,60);
        ta.setText(textArea);
        textAreaPanel.add(ta);
        add("Center", textAreaPanel);
        
        Panel p = new Panel();
        p.setLayout(new FlowLayout());
        Button yes = new Button("Yes");
        yes.addActionListener(this);
        p.add(yes);
        Button no = new Button("No");
        no.addActionListener(this);
        p.add(no);
        add("South", p);
        
        setLocation(100, 200);
        pack();

    }
 
Example 16
Source File: CycleThroughFrameTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void createAndShowInstructionFrame() {
    Button passButton = new Button("Pass");
    passButton.setEnabled(true);

    Button failButton = new Button("Fail");
    failButton.setEnabled(true);

    TextArea instructions = new TextArea(12, 70);
    instructions.setText(TEST_INSTRUCTIONS);

    instructionFrame = new Frame("Test Instructions");
    instructionFrame.add(passButton);
    instructionFrame.add(failButton);
    instructionFrame.add(instructions);
    instructionFrame.setSize(200,200);
    instructionFrame.setLayout(new FlowLayout());
    instructionFrame.pack();
    instructionFrame.setVisible(true);

    passButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
    });

    failButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
        throw new RuntimeException(FAIL_MESSAGE);
    });
}
 
Example 17
Source File: CycleThroughFrameTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void createAndShowInstructionFrame() {
    Button passButton = new Button("Pass");
    passButton.setEnabled(true);

    Button failButton = new Button("Fail");
    failButton.setEnabled(true);

    TextArea instructions = new TextArea(12, 70);
    instructions.setText(TEST_INSTRUCTIONS);

    instructionFrame = new Frame("Test Instructions");
    instructionFrame.add(passButton);
    instructionFrame.add(failButton);
    instructionFrame.add(instructions);
    instructionFrame.setSize(200,200);
    instructionFrame.setLayout(new FlowLayout());
    instructionFrame.pack();
    instructionFrame.setVisible(true);

    passButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
    });

    failButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
        throw new RuntimeException(FAIL_MESSAGE);
    });
}
 
Example 18
Source File: CycleThroughFrameTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void createAndShowInstructionFrame() {
    Button passButton = new Button("Pass");
    passButton.setEnabled(true);

    Button failButton = new Button("Fail");
    failButton.setEnabled(true);

    TextArea instructions = new TextArea(12, 70);
    instructions.setText(TEST_INSTRUCTIONS);

    instructionFrame = new Frame("Test Instructions");
    instructionFrame.add(passButton);
    instructionFrame.add(failButton);
    instructionFrame.add(instructions);
    instructionFrame.setSize(200,200);
    instructionFrame.setLayout(new FlowLayout());
    instructionFrame.pack();
    instructionFrame.setVisible(true);

    passButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
    });

    failButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
        throw new RuntimeException(FAIL_MESSAGE);
    });
}
 
Example 19
Source File: UpdatePopupMenu.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void createInstructionUI() {
    mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
    layout = new GridBagLayout();
    mainControlPanel = new Panel(layout);
    resultButtonPanel = new Panel(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    String instructions
            = "INSTRUCTIONS:"
            + "\n   1. Click on the System Tray Icon"
            + "\n   2. Click on any of the displayed Menu items"
            + "\n   3. Repeat step 1 and count the number of items in the "
            + "Menu"
            + "\n   4. The number of items in the Menu should increase by 1"
            + "\n   5. Repeating steps 1, 2 and 3 should not break 4th step"
            + "\n   6. Click Fail if the 4th step is broken, Otherwise "
            + "click Pass ";

    instructionTextArea = new TextArea();
    instructionTextArea.setText(instructions);
    instructionTextArea.setEnabled(false);
    instructionTextArea.setBackground(Color.white);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainControlPanel.add(instructionTextArea, gbc);

    passButton = new Button("Pass");
    passButton.setName("Pass");
    passButton.addActionListener(this);

    failButton = new Button("Fail");
    failButton.setName("Fail");
    failButton.addActionListener(this);

    gbc.gridx = 0;
    gbc.gridy = 0;
    resultButtonPanel.add(passButton, gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    resultButtonPanel.add(failButton, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    mainControlPanel.add(resultButtonPanel, gbc);

    mainFrame.add(mainControlPanel);
    mainFrame.pack();
    mainFrame.setVisible(true);
}
 
Example 20
Source File: ActionEventTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public ActionEventTest() {
    try {
        robot = new Robot();
    } catch(AWTException e) {
        throw new RuntimeException(e.getMessage());
    }

    button = new Button("ClickMe");
    button.setEnabled(true);

    instructions = new TextArea(10, 50);
    instructions.setText(
    " This is a manual test\n" +
    " Keep the Alt, Shift & Ctrl Keys pressed &\n" +
    " Click 'ClickMe' button with left mouse button\n" +
    " Test exits automatically after mouse click.");

    add(button);
    add(instructions);
    setSize(400,400);
    setLayout(new FlowLayout());
    pack();
    setVisible(true);
    robot.waitForIdle();

    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            int md = ae.getModifiers();
            int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                    | ActionEvent.SHIFT_MASK;

            isProgInterruption = true;
            mainThread.interrupt();
            if ((md & expectedMask) != expectedMask) {
                throw new RuntimeException("Action Event modifiers"
                    + " are not set correctly.");
            }
        }
    });
}