Sitemap

Amicuk Programming Answers

FocusListener and other listener problem

-0001-11-30   Views:0

Advertisement

I don't know why i can't catch Deactivated and LostFocus and other relevant event. I try to make a simplepanel as Popup because Jpopupmenu have some problem. please take a look. regards thanks import java.awt.BorderLayout; import java.awt.event.Actio

I don't know why i can't catch Deactivated and LostFocus and other relevant event.
I try to make a simplepanel as Popup because Jpopupmenu have some problem.
please take a look.
regards thanks
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JWindow;
* Created on Jun 1, 2006
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
* @author varamthanapon
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
public class SampleMain extends JApplet implements ActionListener,
          WindowFocusListener, ComponentListener, WindowListener {
     private JButton m_objJButton = null;
     private PopupPanel m_objPopupPanel = null;
     public SampleMain() {
          this.getContentPane().setLayout(new BorderLayout());
          JPanel mainPanel = new JPanel();
          mainPanel.setSize(500, 500);
          mainPanel.setLocation(500, 500);
          mainPanel.add(new JLabel("XXX"), BorderLayout.NORTH);
          this.getContentPane().add(mainPanel);
          JButton xbutton = new JButton("xxx");
          this.getContentPane().add(xbutton, BorderLayout.WEST);
          xbutton.addActionListener(this);
          m_objPopupPanel = new PopupPanel(this);
          this.addFocusListener(m_objPopupPanel);
          this.show();
     public class PopupPanel extends JWindow implements FocusListener {
          public PopupPanel(SampleMain obj) {
               this.addWindowFocusListener(obj);
               this.addComponentListener(obj);
               this.addWindowListener(obj);
          * (non-Javadoc)
          * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
          public void focusGained(FocusEvent e) {
               // TODO Auto-generated method stub
               JOptionPane.showMessageDialog(new JPanel(), "XXX");
          * (non-Javadoc)
          * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
          public void focusLost(FocusEvent e) {
               // TODO Auto-generated method stub
               JOptionPane.showMessageDialog(new JPanel(), "XXX");
     * (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          m_objPopupPanel.setSize(200, 50);
          m_objPopupPanel.setLocation(200, 50);
          m_objPopupPanel.show();
     * (non-Javadoc)
     * @see java.awt.event.WindowFocusListener#windowGainedFocus(java.awt.event.WindowEvent)
     public void windowGainedFocus(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowGainedFocus");
     * (non-Javadoc)
     * @see java.awt.event.WindowFocusListener#windowLostFocus(java.awt.event.WindowEvent)
     public void windowLostFocus(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowLostFocus");
     * (non-Javadoc)
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
     public void componentResized(ComponentEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "componentResized");
     * (non-Javadoc)
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
     public void componentMoved(ComponentEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "componentMoved");
     * (non-Javadoc)
     * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
     public void componentShown(ComponentEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "componentShown");
     * (non-Javadoc)
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
     public void componentHidden(ComponentEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "componentHidden");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
     public void windowOpened(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowOpened");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
     public void windowClosing(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowClosing");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
     public void windowClosed(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowClosed");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
     public void windowIconified(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowIconified");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
     public void windowDeiconified(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowDeiconified");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
     public void windowActivated(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowActivated");
     * (non-Javadoc)
     * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
     public void windowDeactivated(WindowEvent e) {
          // TODO Auto-generated method stub
          JOptionPane.showMessageDialog(new JPanel(), "windowDeactivated");
}

The replay answer
Advertisement
I believe it's because Windows which don't have a visible parent frame are, by default, not focusable. Therefore they're never activated or focused.
For the window to become focusable it needs a visible parent. Have a look at Window.isFocusableWindow method's Javadoc for information about how this works.
There's also no point trying to force the window to be focusable using setFocusableWindowState - it still won't work without the visible parent frame.
What's the problem with JPopupMenu? It seems unlikely that you'll write something better than that.
Alternatively, you could try using an undecorated JDialog. Personally, I'd try resolving your differences with JPopupMenu!
Hope this helps.

Go to See the other 7 answers

FocusListener and other listener problem

Category:DefaultRelease time:-0001-11-30Views:130

I don't know why i can't catch Deactivated and LostFocus and other relevant event. I try to make a simplepanel as Popup because Jpopupmenu have some problem. please take a look. regards thanks import java.awt.BorderLayout; import java.awt.event.Actio[More]

Message Listener Problem (iDoc)

Category:DefaultRelease time:2015-10-11Views:130

I am receiving an iDoc successfully in the Message Listener within Mii.  I have created a Processing Rule for the Message Type and tied it to a simple BLS.  The BLS has an XML input parameter which is selected in the Processing Rule. The BLS simply m[More]

HELP!!! Listener problem on AIX 4.1 with oracle 7.2.2.0

Category:DefaultRelease time:2015-10-11Views:130

When I try to do "lnsrctl start" (or stop) the server give to me the error below: Connecting to (ADDRESS=(PROTOCOL=IPC)(KEY=ora7)) TNS-12224: TNS:no listener TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener[More]

Oracle Listener Problem

Category:DefaultRelease time:2015-10-11Views:130

I am having a problem starting the Oracle Listener after a system crash on Windows NT. However, if I first connect to the internet and then try to restart, everything works ok. Why should I have to connect to the internet with my laptop in order to s[More]

9.2 and 10g on same machine, listener problem

Category:DefaultRelease time:2015-10-11Views:130

Hi, i had a 10g db on a solaris server. then i installed a 9.2 database on this server. I know that i should use the 10g listener for 9.2 database. But i cant manage to configure it correctly. The 10g listener name is LISTENER and 9.2 listener name i[More]

OAS 4.0.8 http listener problems

Category:DefaultRelease time:2015-10-11Views:130

I am running OAS 4.0.8 on NT w/ SP5. I followed the instructions for install in the latest (Jan 2000) release notes. The problem I am having is with the listeners. The admin and www default listeners start up fine, but if I create a new listener, it[More]

Listener problem

Category:DefaultRelease time:2015-10-11Views:130

Hello, I have created new database and added connection string in to tnsnames.ora file but i am not able to connect with new database remotely. my tnsnames.ora file $ cat tnsnames.ora # tnsnames.ora Network Configuration File: /opt/appl/oracle/produc[More]

Menu/submenu managing and Event Listening problem

Category:DefaultRelease time:2015-10-11Views:130

Hi guys, I'm creating a flashwebsite and I've got a problem with submenu appearing/disappering. What is extremely easy in html/jquery is taking me overburned in actiuonscript: make appear a submenu only when the mouse cursor is over its button and no[More]

Parallel Port Listener problem

Category:DefaultRelease time:2015-10-11Views:130

hello everyone, I have downloaded the javax.comm package and installed it as given in the installation instructions. I can print my files using the javax.comm classes. But i do not get the Parallel Port Event even if i register a listener. Also for a[More]

HTTP Listener problems

Category:DefaultRelease time:-0001-11-30Views:130

Good day all, I have some problems regarding HTTP Listener: 1. I cannot startup my www listener on port 80, only Node Manager listener can be started. It gives out the errors: OWS-08811 & OWS-08851. 2. I even cannot either view or edit the configurat[More]

Upgrade from 9i to 10g, solaris 8 listener problems now...

Category:DefaultRelease time:-0001-11-30Views:130

I recently upgraded some databases from 9i to 10g. In an attempt to punt on the 9i listener - I attempted to start the 10g version of the listener which is producing the following error: -----paste lsnrctl startLSNRCTL for Solaris: Version 10.1.0.2.0[More]

Hot
I use keynote 5.1 and love it.  I tried Keynote 6 and do not like it. My problem is that I am bombarded by popups asking me to update to Keynote 6 This reduce my work speed to a snails pace. Would be most delighted to find a solution to the problem. [More]
I just picked up a new Mac mini, and a new Apple wireless keyboard. I'm setting up the mini for the first time and i can't complete the setup because the new wireless keyboard doesn't seem to be recognized during the initial mini setup process. Shoul [More]
Hi, I have messages that are stuck in a specific queue seen in SMQ2. when I checked the status of the queue, it is RUNNING and the first message in the queue has a statusText 'Transaction Executing'. We have deregister - register, activate, unlock, l [More]
I'm having problems partitioning in boot camp, so I read that I should defrag my drive. I'm getting the error because it can't move certain files. So I'm using iDefrag, but it won't let me use most of the defrag options because I'm using the disk it [More]
I needed to change settings for mail but the 'settings' icon has disappeared.  How do I get the icon backYou cannot delete it. It is likely on another page or in a folder. If it is not there, then reset your home screen layout: iPod touch User Guide [More]
Greetings all, (My apologies ahead of time if this is the wrong forum.) I posted a while ago on some of Amazon's forums looking for Flex (Actionscript really) libraries for interacting with Amazon's S3 service, but unfortunately received no responses [More]
Hi , Could anyone pls tell me the difference between the calculation manager and business rules?Calculation manager is a web component that is designed to manage business rules from a web interface. It is enabled to build calculations also using a gr [More]
I have downloader Adobe Reader 8.1.2-Dansk, but when I will install it I get this message: Fundet program( AC76BA86-7AD7-1030-7B44-A8100000000) Kommandolinie: UPGR..., and the program interrops. I have ben in the REGEDIT and deletet alle about Adobe [More]
Hi all. Ive got an application that im working on where i need to run 2 different programs and send keystrokes to both of them (separately) with labview.  Is there a way to give focus to each of the two program, then send keystrokes? i have been sear [More]
I received the following error when reading an Excel sheet directly into a target template table.  Nothing fancy, but the error pops up immediately.  I have found the problem and am posting the error and resolution to hopefully help others,   -rs- 69 [More]