Results 1 to 4 of 4
- 02-01-2010, 06:50 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
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,and a test in my code states that it is!Java Code:textArea.setEditable(true);
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.Java Code:if (textArea.isEditable()) { System.out.println("text area is editable"); }
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 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(); } }); } }
- 02-01-2010, 07:02 PM #2
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
Your task calls for a JDialog: How to Make Dialogs.
- 02-01-2010, 07:43 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
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?
-
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
-
Java Popup .hide() method is leaving a grey box in the shape of the JTextArea I use.
By shawleigh17 in forum AWT / SwingReplies: 3Last Post: 03-03-2011, 04:59 PM -
Tab key in JTextArea
By KristoZ in forum New To JavaReplies: 1Last Post: 09-25-2009, 07:27 PM -
About JTEXTAREA
By makpandian in forum AWT / SwingReplies: 4Last Post: 03-19-2009, 06:53 AM -
How to add a shortcut key from JTextArea
By sukatoa in forum Advanced JavaReplies: 2Last Post: 01-28-2008, 08:39 AM -
JTextArea
By saytri in forum New To JavaReplies: 0Last Post: 01-13-2008, 01:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks