Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - How do I click through a JTextArea ?

 
Thread Tools Search this Thread
Old 02-08-2004, 08:39 PM   #1
Default How do I click through a JTextArea ?


Consider the applet below. There is a small JTextArea sitting in the
glass pane. There are 3 JButtons sitting in a JPanel that is sitting
in the content pane. One is completely under the JTextArea, one is
half in and half out, & the last is completely outside it (at least I
hope thats what it looks like on your machine.) The idea is when you
click the disable button the JTextArea is disabled and you can click
on the button that's underneath it.
But it doesn't work that way. even when the JTextArea is disabled the
mouse still cant click through it.
Is there some way to make the JTextArea completely invisible to the
mouse so I can click through it? I know setVisible(false) on the glass
panel will work but I only want it to be invisible to the mouse, not
my eyes.
Thanks.

/* <applet code="MyTest14" width="400" height="100"></applet> */
// testing glass panes
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;

public class MyTest14 extends JApplet implements MouseListener
{
TextPanel textPanel;
JPanel buttonPanel;
JButton underButton, enableButton, disableButton;
JTextArea jta;

public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.setBackground(Color.WHITE);

underButton = new JButton("Under textarea");
underButton.addMouseListener(this);
enableButton = new JButton("Enable textarea");
enableButton.addMouseListener(this);
disableButton = new JButton("Disable textarea");
disableButton.addMouseListener(this);

buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(underButton, "West");
buttonPanel.add(enableButton, "Center");
buttonPanel.add(disableButton, "East");

jta = new JTextArea();
jta.setPreferredSize(new Dimension(200,80));
jta.setOpaque(false);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);

textPanel = new TextPanel();
textPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
textPanel.add(jta);
jta.setBorder(BorderFactory.createLineBorder(Color .black));

contentPane.add(buttonPanel);

setGlassPane(textPanel);

textPanel.setVisible(true);
}

public void mouseClicked(MouseEvent e)
{
if (e.getSource() == enableButton) { jta.setEnabled(true); }
else if (e.getSource() == disableButton) { jta.setEnabled(false); }
else if (e.getSource() == underButton) { System.out.println("You
reached the under button!"); }
}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}

class TextPanel extends JPanel
{
public TextPanel()
{
super();
setOpaque(false);
}

public void paintComponent(Graphics g) { super.paintComponent(g); }
}
}


apchar
  Reply With Quote
Old 02-08-2004, 10:37 PM   #2
Andrew Thompson
 
Posts: n/a
Default Re: How do I click through a JTextArea ?
apchar wrote:
> Consider the applet below. There is a small JTextArea sitting in the
> glass pane. There are 3 JButtons sitting in a JPanel that is sitting
> in the content pane. One is completely under the JTextArea, one is
> half in and half out, & the last is completely outside it (at least I
> hope thats what it looks like on your machine.)


Yes, that is how it appears here.

> ...The idea is when you
> click the disable button the JTextArea is disabled and you can click
> on the button that's underneath it.


I do not know if such a thing is possible,
but I am wonderring why you would force
your users to suffer such a counterituitive GUI?

Is there some purpose to this that I missed
that makes it a good and sensible thing to do?

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology




Andrew Thompson
  Reply With Quote
Old 02-08-2004, 10:52 PM   #3
Andrew Thompson
 
Posts: n/a
Default Re: How do I click through a JTextArea ?
Andrew Thompson wrote:
> apchar wrote:
>> Consider the applet below. There is a small JTextArea sitting in the
>> glass pane.


And before I forget, the GUI Gurus
can be found at news:comp.lang.java.gui

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology




Andrew Thompson
  Reply With Quote
Old 02-09-2004, 12:57 AM   #4
Andrew Hobbs
 
Posts: n/a
Default Re: How do I click through a JTextArea ?

"apchar" <> wrote in message
news: m...
> Consider the applet below. There is a small JTextArea sitting in the


snip

> {
> if (e.getSource() == enableButton) { jta.setEnabled(true); }
> else if (e.getSource() == disableButton) { jta.setEnabled(false); }


The applet works exactly as you have written it. Disabling and Enabling a
component is not going to make it go away. It makes it unresponsive to
commands.

If you want it to go away use jta.setVisible(false) and it works as you
suggest it should.

*However* I presume this is just a test to see how to get something to work.
Because if it isn't (as Andrew Thompson suggested) you need to do some
serious reading of articles on GUI design.

Cheers

Andrew


--
************************************************** ******
Andrew Hobbs PhD

MetaSense Pty Ltd - www.metasense.com.au
12 Ashover Grove
Carine W.A.
Australia 6020

61 8 9246 2026
metasens AntiSpam @iinet dot net dot au


************************************************** *******


> else if (e.getSource() == underButton) { System.out.println("You
> reached the under button!"); }
> }
> public void mouseExited(MouseEvent e) {}
> public void mouseEntered(MouseEvent e) {}
> public void mouseReleased(MouseEvent e) {}
> public void mousePressed(MouseEvent e) {}
>
> class TextPanel extends JPanel
> {
> public TextPanel()
> {
> super();
> setOpaque(false);
> }
>
> public void paintComponent(Graphics g) { super.paintComponent(g); }
> }
> }





Andrew Hobbs
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to activate Remote Assistance with XP using Windows Live Messenger Oziisr General Help Related Topics 0 02-01-2008 04:45 PM
How to make your wonderful photo and video slideshow on DVD kricww@gmail.com DVD Video 0 04-20-2006 07:26 AM
Converting PAL DVDs to NTSC DVDs. Wild Coyote DVD Video 14 10-27-2004 09:58 PM
winsock.dll J A+ Certification 7 07-20-2004 01:01 AM
Latest Tech Fiasco... Ghost A+ Certification 30 01-09-2004 12:15 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46