Results 1 to 4 of 4
  1. #1
    Richy76 is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default JTextArea on PopUp -JTextArea isn't editable

    I am having an issue with putting a JTextArea on a popup panel. When a button is pressed, a popup should appear with a JTextArea on it. This area should be editable (e.g the user should be able to input text into it). There is a button on the pop up which, when pressed, should make the popup disapear (and will ultimately process the text input by the user).

    However I have the problem that the JTextArea is not editable-although I have set it to Edtitable,
    Java Code:
    and a test in my code states that it is!
    Java Code:
    if (textArea.isEditable()) {
    				System.out.println("text area is editable");
    I have used JTextArea before, and I don't usually have a problem making it editable-but there seems to be some issue when it is placed on a pop up.

    This is a for a project where I am creating a messaging application. My idea is that the user will press a button to start composing a message. The popup window with the JTextArea will appear and he will input his message. He will then press a send button which will make the window disappear and send the message.

    If anyone can point out where I'm going wrong-or else suggest a better way of doing this (perhaps a different set of components to use), I will be very grateful.

    thanks in advance.

    Here is the full code of my program.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextAreaTest extends JPanel implements ActionListener {
    	protected JTextArea textArea;
    	protected JButton myButton;
    	protected Popup popup;
    	protected JButton anotherButton;
    	protected JPanel myPanel;
    	private final static String newline = "\n";
    	public  TextAreaTest() {
    		super(new GridBagLayout());	
    		myButton = new JButton("press this"); //popup window appears when this is pressed
    		anotherButton = new JButton("anotherButton"); //button on popup. closes popup when pressed
    		textArea = new JTextArea(5, 20);
    		textArea.setEditable(true); //note: set to true!
    		textArea.append("this is the text Area");
    		JScrollPane scrollPane = new JScrollPane(textArea);
    		myPanel = new JPanel(); //this is the popup panel
    	public void actionPerformed(ActionEvent e) {
    		String command = e.getActionCommand();
    		if(command.equals("myButton")) {
    			PopupFactory factory = PopupFactory.getSharedInstance();
    			popup = factory.getPopup(null, myPanel, 0, 0);
    			if (textArea.isEditable()) { 
    				System.out.println("text area is editable");
    		} else if (command.equals("anotherButton")) {
    			System.out.println("another Button pressed");
    			String text = textArea.getText();
    	private static void createAndShowGUI() {
    		//Create and set up the window.
    		JFrame frame = new JFrame("TextDemo");
    		//Add contents to the window.
    		frame.add(new TextAreaTest());
    		//Display the window.
    	public static void main(String[] args) {
    		//Schedule a job for the event dispatch thread:
    		//creating and showing this application's GUI.
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Pittsburgh, PA
    Rep Power


    Your task calls for a JDialog: How to Make Dialogs.

  3. #3
    Richy76 is offline Member
    Join Date
    Feb 2010
    Rep Power


    Thanks. I've had a quick look at that link. Immediately I don't see any mention of JTextArea there

    Can you just briefly tell me if it is definitely the case that you can put a JTextArea on a JDialog?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Why not have a look at it again, in depth. A JDialog is a root container just like a JFrame. You can just about put any component in it (actually, like a JFrame, in its contentPane), including JTextAreas, JPanels, ... whatever.

Similar Threads

  1. Replies: 3
    Last Post: 03-03-2011, 05:59 PM
  2. Tab key in JTextArea
    By KristoZ in forum New To Java
    Replies: 1
    Last Post: 09-25-2009, 07:27 PM
  3. About JTEXTAREA
    By makpandian in forum AWT / Swing
    Replies: 4
    Last Post: 03-19-2009, 07:53 AM
  4. How to add a shortcut key from JTextArea
    By sukatoa in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 09:39 AM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 02:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts