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
My boos has an ical and he wants to sync google calendar in it, how can we do that?Hi, To set up Google Calendar in iCal on Lion: Open iCal > Preferences > Accounts, and click the plus button to set up a new account. The pop-up dialog has a drop-dow [More]
We operate tens of macbooks at our campus for student loans. We are trying to cut on the power consumption of the loans operation. I am interested to know how much power does the power brick consume when: a) nothing is connected to the MagSafe jack. [More]
I just installed 10.8.3 on my retina and the new windows 8 driver with a fresh bootcamp install.  Good news is the bluetooth works to keyboard and trackpad, both my external thunderbolt monitors work, the resolution is now correct at 2880x1880. Only [More]
Hi Experts I have configured a new HR Form (Adobe) using HRASR_DT and the other SPRO links in ECC but when i log on to Portal I do not see this new form. I have configured the Process for the ISR Scenario same as the other forms but other forms are v [More]
Here's the background information: 1. I've been working with a Mighty Mouse via a D-Link DBT-120 Nodule since the MM came out and everything was fine. 2. Spilled orange juice on it and got a new one. 3. New one worked for about three weeks and then j [More]
Dear All, Can we remove the message-id from the auto-reply? in an auto-reply the message bounces back to the user including in the body part the following: Message-id: <[email protected]> Date: Thu, 31 Jul 2008 21:36:08 +0300 From: [email protected] [More]
Yes, the warning then says 'A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete. I Script: js/ff_browser:204 Continue OR Stop ScriptStart Firefox in [More]
Has anyone else experienced an error when attempting to classify an unclassified rogue AP? For example, we have a rogue AP we would like to classify as Friendly/External however the WLC (WISM2 - 7.4.110.0) throws an error "Unable to change rogue stat [More]
Hi, I am new to the Oracle UCM 11g. i am unable to full text index the content files that are check-in into the Oracle UCM. I have added the below entries in config.cfg file: SearchIndexerEngineName=OracleTextSearch IndexerDatabaseProviderName= Syste [More]
Hi Team, While settling service order to sales order via KO88, our Product Costs settled to one secondary cost element say-962100 & Labor Costs settled to secondary cost elemnt-say 968000. We need to pass journal entry for transfer labour cost to GL [More]