![]() |
|
|
|||||||
![]() |
Java - How do I click through a JTextArea ? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
"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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |