aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Right Click in a TextArea problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Right Click in a TextArea problem" Watch "Right Click in a TextArea problem" New topic
Author

Right Click in a TextArea problem

eLL Pascual
Greenhorn

Joined: May 22, 2008
Posts: 21
What seems to be the problem when you see this error message?

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: parent not showing on screen

The error appears when I place the 'textArea.addActionListener(this);' right after 'textArea = new JTextArea(5,10);'

Just like this:

code:
----------------------------------------------------------------------------

textArea = new JTextArea(5,10);
textArea.addMouseListener(this);

----------------------------------------------------------------------------

when they are like this there is no error and no right click.

code:
----------------------------------------------------------------------------

textArea.addMouseListener(this);
textArea = new JTextArea(5,10);

----------------------------------------------------------------------------

I want my textArea to have a right click but it is not working.

Is there anything missing here?

code:
----------------------------------------------------------------------------

public void mousePressed(MouseEvent me)
{
System.out.print("Mouse Right-Clicked!");//Test if the mousePressed is working
if(me.getModifiers() != 0){
popup.show(this, me.getX(), me.getY());

}
}

public void mouseClicked(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}

----------------------------------------------------------------------------



To give you an overview of my code, this is it. My textArea is inside:

code:
----------------------------------------------------------------------------

public Container createContentPane(){

...
textArea = new JTextArea(5,10);
textArea.addMouseListener(this);
...
return contentPane;

}

----------------------------------------------------------------------------

which is called inside:


code:
----------------------------------------------------------------------------

public static void createShowGUI(){

...
notepad notpad = new notepad();//class instance
frame.setContentPane(notpad.createContentPane());

}

----------------------------------------------------------------------------

I already tried to put the 'textArea.addMouseListener(this);' inside the constructor but it is not
working.

Please help me. Thanks!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
First off, I advise you not to have your GUI class implement the MouseListener. It would be cleaner to just create an anonymous inner class. Next of all, you may have better luck getting decent responses if you show us compilable code. I don't want to see your whole program, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem, in other words, an SSCCE (Short, Self Contained, Correct (Compilable), Example). For more info on SSCCEs please look here:

http://homepage1.nifty.com/algafield/sscce.html

For example, here is an example of using an anonymous inner class for a MouseListener. I actually use a MouseAdapter so I don't have to have all of those empty mouse methods:


Last, don't forget to use code tags so that your code will retain its formatting and be readable.

Good luck!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Right Click in a TextArea problem
 
Similar Threads
Insertion in JTextArea
right click with Jlist
undoProblem
JTextArea setSelection not highliting
mousePressProblem