Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-01-2010, 07:50 PM
Member
 
Join Date: Feb 2010
Posts: 2
Rep Power: 0
Richy76 is on a distinguished road
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,
Code:
textArea.setEditable(true);
and a test in my code states that it is!
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.
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
		myButton.setActionCommand("myButton");
		myButton.addActionListener(this);
		add(myButton);

		anotherButton = new JButton("anotherButton"); //button on popup. closes popup when pressed
		anotherButton.setActionCommand("anotherButton");		
		anotherButton.addActionListener(this);



		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
		myPanel.add(anotherButton);
		myPanel.add(scrollPane);
	}

	public void actionPerformed(ActionEvent e) {

		String command = e.getActionCommand();

		if(command.equals("myButton")) {
			PopupFactory factory = PopupFactory.getSharedInstance();
			popup = factory.getPopup(null, myPanel, 0, 0);

			popup.show();

			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();
			System.out.println(text);

			popup.hide();
		}






	}



	private static void createAndShowGUI() {
		//Create and set up the window.
		JFrame frame = new JFrame("TextDemo");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Add contents to the window.
		frame.add(new TextAreaTest());

		//Display the window.
		frame.pack();
		frame.setVisible(true);
	}

	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() {
				createAndShowGUI();
			}
		});
	}


}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-01-2010, 08:02 PM
Senior Member
 
Join Date: Aug 2009
Location: Pittsburgh, PA
Posts: 265
Rep Power: 1
zweibieren is on a distinguished road
Default
Your task calls for a JDialog: How to Make Dialogs.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-01-2010, 08:43 PM
Member
 
Join Date: Feb 2010
Posts: 2
Rep Power: 0
Richy76 is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-01-2010, 08:51 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,504
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Popup .hide() method is leaving a grey box in the shape of the JTextArea I use. shawleigh17 AWT / Swing 2 01-13-2010 05:54 AM
Tab key in JTextArea KristoZ New To Java 1 09-25-2009 08:27 PM
About JTEXTAREA makpandian AWT / Swing 4 03-19-2009 07:53 AM
How to add a shortcut key from JTextArea sukatoa Advanced Java 2 01-28-2008 09:39 AM
JTextArea saytri New To Java 0 01-13-2008 02:07 AM


All times are GMT +2. The time now is 01:20 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org