Frame in focus

i have 2 frames. how do i work out which one is in focus i.e. the last frame clicked?

Here's an example that uses a focus listener:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame implements FocusListener {
    private JLabel focusLabel;
    public Test (int x, int y, int xCount, int yCount) {
        super ("Have I got focus?");
        focusLabel = new JLabel ();
        focusLabel.setHorizontalAlignment (SwingConstants.CENTER);
        getContentPane ().add (focusLabel);
        addFocusListener (this);
        Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
        int width = (screenSize.width - 100) / xCount;
        int height = (screenSize.height - 100) / yCount;
        setSize (width - 1, height - 1);
        setLocation (50 + x * width, 50 + y * height);
        setDefaultCloseOperation (EXIT_ON_CLOSE);
        setResizable (false);
        show ();
    public void focusGained (FocusEvent event) {
        setFocusLabelText ("I've got focus!");
    public void focusLost (FocusEvent event) {
        setFocusLabelText ("");
    private void setFocusLabelText (String text) {
        focusLabel.setText (text);
        focusLabel.invalidate ();
        validate ();
    public static void main (String[] parameters) {
        try {
            int xCount = Integer.parseInt (parameters[0]);
            int yCount = Integer.parseInt (parameters[1]);
            for (int x = 0; x < xCount; x ++) {
                for (int y = 0; y < yCount; y ++) {
                    new Test (x, y, xCount, yCount);
        } catch (Exception exception) {
            System.err.println ("Usage: java Test [xCount] [yCount]");
            System.exit (-1);
}Kind regards,
Levi

Similar Messages

  • Still Frames, Losing focus, PNG

    I'm put some still frames into my timeline, however, when I playback the stills, it loses focus. When I pause the timeline on the stills, it becomes fine, perfect focus and everything. (These stills are being taken from a seperate digital camera.)
    The stills I put in are jpg format...should they be in PNG format? How do I convert it to PNG format? Thanks in advance.
    I have:
    FInal Cut Pro 3.0
    Mac OS X 10.4.10

    Shane's Stock Answer #2: Blurry playback
    ONLY JUDGE THE QUALITY OF YOUR MATERIAL ON AN EXTERNAL NTSC MONITOR, OR AT LEAST A TV.
    1. Disable overlays on the canvas
    2. Make sure you've rendered everything (no green bars at the top of the timeline
    http://docs.info.apple.com/article.html?artnum=24787
    Video playback requires large amounts of data and many computations. In order to maintain frame rate and be viewable at a normal size, only about one-fourth of the DV data is used in displaying the movie to the screen. However, the DV footage is still at full quality, and is best viewed thru a TV or NTSC monitor routed thru your camera or deck.
    Shane

  • Detect if JPanel is in the active frame or focused window

    Hi,
    I have JPanel, and I want to determine if it is in an active JInternalFrame (isSelected() == true), or if its frame or dialog has focus.
    I know I can use the KeyboardFocusManager, so do I just search up the container heirarchy looking for the focus owner?

    I found that it keeps looking up and up the heirarchy untl it hits the top-level container, so there are cases where you have two internal frames (one active, one deactiveated), and both return true since their parent is the active window. I found a similar way:
    // This fragment stops at the active frame, and won't search its parent.
    return SwingUtilities.isDescendingFrom(this, manager.getPermanentFocusOwner());Thanks for your help!

  • How to make Internal Frame on Focus

    Hi All,
    i have an application where in i have a JInternalFrame within in A JFrame.
    Queries:
    1.I want to make JInternalFrame focused,(without clicking on any portoion of Internal Frame) once i run the apllication(java Demo)
    2.i want to fix the JInternal Frame.(Non movable)
    //Demo.java
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;     
    import javax.swing.event.*;     
    import javax.swing.border.*;          
    public class Demo extends JFrame implements ActionListener {
    static JDesktopPane desk;
    String labelstr="Test ";
    JPanel contentpane;
    JLabel titlelabel;
    public Demo() {
              setTitle("Swing Test");
                    contentpane=(JPanel)getContentPane();
                    contentpane.setLayout(new BorderLayout());
                    desk=new JDesktopPane();     
                    desk.setBackground(Color.gray);
                    contentpane.add("Center",desk);
                    titlelabel=new JLabel(labelstr);
                    titlelabel.setForeground(Color.black);
                    titlelabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
                    getContentPane().add(titlelabel,BorderLayout.SOUTH);            
              public void actionPerformed(ActionEvent e) {
                 public static void main(String args[]) {     
                    try  {
                      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                     }catch(Exception e) {
                                               System.out.println("Error loading L&F:"+e);     
                                               JOptionPane.showMessageDialog(null,e);
                    JFrame frame=new Demo();
                    frame.setSize(800,600);
                    frame.setVisible(true);
                      InternalFr jif=new InternalFr();
                      jif.start();
                    frame.addWindowListener(new CloseWindow());
           class CloseWindow extends WindowAdapter {
             public void windowClosing(WindowEvent we) {
                 Window w=we.getWindow();
                 w.dispose();
                 System.exit(0);
          }//InternalFr.java
    import java.io.*;
         import java.net.*;
         import java.lang.*;
         import java.awt.*;
         import java.awt.event.*;
         import javax.swing.*;
         import javax.swing.border.*;
         import javax.swing.text.*;
         public class InternalFr extends JInternalFrame {
             JLabel jlName, jlPass;
             static JTextField jtName,jtPass;
                 JButton submit,cancel;
            public InternalFr() {  
              super( "InternalFr");
              Icon img=new ImageIcon("Neticon.gif");
              setFrameIcon(img);
              JPanel contentpane=(JPanel)getContentPane();
               contentpane.setLayout(null);
              JPanel mainpanel=new JPanel();
              mainpanel.setLayout(null);
              mainpanel.setBounds(0,0,290,180);
              jlName=new JLabel("Username   :");
              jlName.setBounds(20,20,180,20);
              jlName.setForeground(Color.black);
              jtName=new JTextField();
              jtName.setBounds(150,20,100,20);
              mainpanel.add(jtName);
              mainpanel.add(jlName);
              jlPass=new JLabel("Password   :");
              jlPass.setBounds(20,50,180,20);
              jlPass.setForeground(Color.black);
              jtPass=new JTextField();
              jtPass.setBounds(150,50,100,20);
              mainpanel.add(jlPass);
              mainpanel.add(jtPass);
              JPanel buttonpanel=new JPanel();
              buttonpanel.setLayout(null);
              buttonpanel.setBounds(30,90,215,30);
              buttonpanel.setBorder(new EtchedBorder(EtchedBorder.RAISED));
              submit=new JButton("Submit");
              submit.setMnemonic('O');
              submit.setBounds(5,5,100,20);
              buttonpanel.add(submit);
              submit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                 if(ae.getSource()==submit)  {
            cancel=new JButton("Cancel");
              cancel.setMnemonic('C');
              cancel.setBounds(110,5,100,20);
              buttonpanel.add(cancel);
              cancel.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent ae) {
                      Object obj=ae.getSource();
                     if(obj==cancel){
                          System.exit(0);
           contentpane.add(buttonpanel);
           contentpane.add(mainpanel);
        public void start()  {
             InternalFr at=new InternalFr();
             at.setSize(290,180);
            at.setLocation(220,150);
            at.setVisible(true);
            Demo.desk.add(at);
      }Thanks
    Mohan

    To give focus to an internal frame, do the following (where iFrame is your internal frame):try {
        iFrame.setIcon( false );  // In case it is minimized
        iFrame.moveToFront();     // Make sure it is in front
        iFrame.requestFocus();    // Ask for focus
        iFrame.setSelected( true );  // Select it
    } catch( java.beans.PropertyVetoException pve ) {
    }

  • Frames and Focus Borders

    Hi I have two questions about swing components?
    First One :
    I want to change the focus border of any component. For example if a JButton on a panel has focus, I want to draw a yellow border around it. I cannot find an easy way to do it.Is there a way to do it?
    Second One:
    I want to change a JFrame's decoration.For example I want to show the title in the middle of the title bar. Is there a way to do it?
    Thanks for help.

    Hi I have two questions about swing components?
    First One :
    I want to change the focus border of any component. For example if a JButton on a panel has focus, I want to draw a yellow border around it. I cannot find an easy way to do it.Is there a way to do it?
    Second One:
    I want to change a JFrame's decoration.For example I want to show the title in the middle of the title bar. Is there a way to do it?
    Thanks for help.

  • Switching windows in Linux/Firefox loses keyboard focus. Workarounds?

    Hi,
    I've been stumbling on an issue in which an applet gets into a state where it can receive mouse events but not keyboard events. This state occurs some of the time when switching from a non-modal dialog to the applet.
    I've witnessed this behavior on:
    Linux (fc8), Firefox 3.0.10, Java plug-in 1.6.0_13, Gnome 2.20.3
    Sun Solaris (5.10), Firefox 3.0.8, Java plug-in 1.6.0_12, Sun Java Desktop System or CDE
    I can not reproduce this behavior using appletviewer, nor can I reproduce it on the Mac (Opera/Firefox/Safari), nor on Windows (Firefox/IE).
    I've crafted some code that shows the behavior:
    FocusApplet.java:
    import javax.swing.JApplet;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.beans.*;
    public class FocusApplet extends JApplet {
      JTextArea infoText;
        Object activeWindow;
        Object focusOwner;
        Object permanentFocusOwner;
           Applet contains two components.
           NORTH: Text field
           CENTER: Info text
           The info text is updated whenever the following
           KeyboardFocusManager properties change:
              activeWindow
           focusOwner
           permanentFocusOwner
      public void init(){
          JTextField tf = new JTextField("Type here");
          infoText = new JTextArea();
          infoText.setEditable(false);
          infoText.setLineWrap(true);
          infoText.setWrapStyleWord(true);
          infoText.setBorder(new EtchedBorder());
          this.add(infoText, BorderLayout.CENTER);
          this.add(tf, BorderLayout.NORTH);
          KeyboardFocusManager focusManager =
           KeyboardFocusManager.getCurrentKeyboardFocusManager();
          activeWindow=focusManager.getActiveWindow();
          permanentFocusOwner=focusManager.getPermanentFocusOwner() ;
          focusOwner=focusManager.getFocusOwner() ;
          updateText();
          focusManager.addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              if ("focusOwner".equals(prop)) {
                  focusOwner = e.getNewValue();
                  updateText();
              } else if ("permanentFocusOwner".equals(prop)) {
                  permanentFocusOwner = e.getNewValue();
                  updateText();
              } else if ("activeWindow".equals(prop)) {
                  activeWindow = e.getNewValue();
                  updateText();
          // Create non-modal dialog
          JDialog jdl = new JDialog((Frame)null,"Extra dialog",
                        false/*modal*/);
          jdl.setSize (300,550);
          jdl.setVisible(true);
        public void updateText() {
         infoText.setText("Active window: "+getName(activeWindow)+
              "\nFocus owner: "+getName(focusOwner)+
            "\nPermanent focus owner: "+getName(permanentFocusOwner));
        public String getName(Object obj) {
         return (obj==null) ? "null" : obj.getClass().getName();
    }Applet HTML:
    <applet code="FocusApplet.class" width="400" height="400"></applet>When I run this applet, I can click on the text field ("Type here") and enter text. Then, I switch between the empty dialog box and the applet using the window manager. (I.e., clicking on the dialog, then clicking on the applet.) Sometimes I see the following Keyboard Focus settings when I bring the applet to the front:
    Active window: sun.plugin.viewer.frame.XNetscapeEmbeddedFrame
    Focus owner: javax.swing.JTextField
    Permanent focus owner: javax.swing.JTextField
    In this case, clicking on the text field will allows the user to edit text. Good! However, 10%-50% of the time I get the following settings after I bring the applet to the front:
    Active window: null
    Focus owner: null
    Permanent focus owner: javax.swing.JTextField
    In this case, I can click on the applet, and I can highlight text in the text field, but I can not edit the text. (No carat appears. Bad!) Since there is no keyboard focus owner, the applet appears non-responsive.
    I have a few questions:
    1. Is this a Java plug-in bug? A Firefox bug? Who do I file a bug with, assuming there's not something I'm missing?
    2. Can anyone suggest a workaround?
    Thanks,
    -David-

    I noticed the problem too. Is there any fix or workaround? Friends using Windows say that all is ok.
    Linux x86_64 (Gentoo), Firefox 3.5.1, jre 1.6.0.15.

  • How to make a frame modal?

    Hei guyz,
    I'm trying to call a frame from another frame (which should basically act like a dialog, but is not a dialog), how can i make this 'child' frame modal, i.e. once im done with the 'child' frame, the focus has to go back to the 'parent' frame and no other component could be opened while a user is working on the 'child' frame.
    Can anyone let me know, how this is possible and is there any other better approach (other than making the child frame, a dialog)?
    Thanks in advance.

    and is there any other better approach How can we suggest a better approach when we don't know why you rejected a modal dialog.
    Based on your requirement:
    once im done with the 'child' frame, the focus has to go back to the 'parent' frame and no other component could be opened while a user is working on the 'child' frame.
    it would appear to me that using an modal dialog is the obvious choice.
    Otherwise I suggest you search the forum. Keywords like "modal jframe" would be a good place to start.

  • Automatically focus JInternalFrame when starting the application...

    Hi,
    I wonder why my JInternalFrame is not selected (focused) when I start the application - in NetBeans GUI editor I have set the following properties to make my JInternalFrame automatically selected when the app starts:
    o enabled
    o selected
    o visible
    Can anyone tell me how to make my JInternalFrame focused?
    Thanks
    - Stephan

    Thanks but unfortunately that didn't solve my problem...
    I even tried the following code excerpt...
    try {
        jInternalFrame1.setSelected(true);
    } catch (java.beans.PropertyVetoException e1) {
        e1.printStackTrace();
    }... but it didn't work - my jInternalFrame1 is not focused on startup. Is this a bug in Java 1.4?
    On the other hand I noticed that the example application (InternalFrameDemo) doesn't focus the first internal frame on startup, too - when creating another internal frame from within the application that frame gets focused...
    http://java.sun.com/docs/books/tutorialJWS/uiswing/components/ex6/InternalFrameDemo.jnlp
    Thanks in advance
    - Stephan

  • Popup status doesn't disappear when moving focus within framesets

    I developed and manage a website that makes extensive use of frames. When I click on a link in one frame that opens a page in an adjacent frame moves focus there. The problem is that the the popup status that appeared in the origin frame displaying the link to the just-opened window doesn't then disappear, but remains visible even though that frame is no longer active. This would appear to be a bug. Can it either be fixed or a work-around suggested? Please don't comment on frames being obsolete. Thanks

    Adding on to original query. In fact this behavior only occurs when transferring to a frame containing a data entry form. Then, if I move the cursor over any other hyperlink, say in the side favorites menu, the popup disappears. Quite annoying, particularly since I previously used the status bar to inform users of valid / invalid input quantities on these forms.

  • JFrame loses focus in Java 1.4

    Hi,
    I am running on Win2k.
    I have two frames open. One has focus (a) and one does not (b). When I move my mouse from (a) over (b), frame (b) "focuses" as if I clicked my mouse in the frame.
    It behaves kind of like some UNIX window managers do where you can cause a window to get focus just by moving your mouse over it (e.g. in window you have to "click" in the window to cause it to get focus).
    Any help would be greatly appreciated.
    Rob

    I have noticed exactly the same behaviour in my
    applicationm which I just happened to have rolled out
    to a customer. it's infuriating. Did you find an
    answer to this? if so please let me know.
    Hmm, can't reproduce it (win2k and jdk1.4.2) - could you post a small example demonstrating the problem?
    Greetings
    Jeanette

  • Want to delete FACE frames (i.e.,  remove photo's analyzed info)

    I can't get rid of FACE frames.  in a photo with many faces, face frames are a nuisance when i try to create focus frames for the pan and zoom tool.  how do i delete them?  clear all frames only gets rid of the FOCUS frames.
    another way to ask the question is  "how do i remove the analyzed data for a photo?"
    thanks in advance.

    makingFamilyVideos
    Just starting my day.
    I think we are now in sync with what you want to do with the Pan and Zoom Tool Frame Hints.
    I have the Face Frames and Focus Frames doing what I want them to do, with and without deletion of an analyzed frame so that a Frame Hint is left. I guess you could think about those Frame Hints as an "AutoSave" of sorts if you change your mind after deletion of an analyzed frame.
    One way to get them out of the question would be "do not use Face Frames" and do your pan from person to person by adding new frames beyond the pre-made 2 when you open the Pan and Zoom workspace. Those Frame hints are generated only when after you delete an analyzed Face frame...no Face frame, no analysis.
    But, what I am doing now is looking for where the information for the Frame hints may be embedded. My best guess was that they are in the Notepad document of the saved/closed project in which you are using the Pan and Zoom Tool.
    However this morning's test results argue against that. This has all the aspect's of People Face Recognition feature of the Pan and Zoom Tool Face Frame that is program related rather than specific to any one project. And, the Pan and Zoom Tool Face Frame is not generating any people thumbnails in the Elements Organizer People when Pan and Zoom Tool's Face Frame is going its thing.
    I found a Face Dector.dll in the Program Files for Premiere Elements 12, but have not been able, so far, to link it with getting rid of the concept of Frame hint.
    More later.
    ATR

  • JFrame focus

    Hi
    I got several JFrame's, where one is the main frame, which detects shortcuts (key pressed events). When a key is pressed other JFrame's are shown or iconized (dependent on their current state). Everything works fine except that my main frame loses focus, when the one of the sub JFrames is iconized (with the setState() method). How do I keep the main frame in focus after changing the state of the sub JFrames? I tried requestFocus, requestWindowFocus(), show() and nothing seems to work, the main frame keeps losing focus...
    Thanks Denker, Denmark

    When a key is pressed other JFrame's are shown or iconized You have multiple JFrames and you only have a problem with one of them? What is different about this frame compared to the others? Isolate the difference and that might help lead to a solution.
    Also, maybe you should be using multiple JDialogs instead of JFrames. Typically an application has one main frame with helper dialogs.

  • Printing an iframe with pdf using javascript is not working in IE8 and above

    I have a problem with printing and Iframe with PDF in IE 8 and above
    Following is my javascript:
    var urlValue="";//Path of the file to be printed
    var div = document.getElementById("printerDiv");
    div.innerHTML = '<iframe src="' + urlValue + '" id="frame" name="frame" style="width:100%;height:100%;"></iframe>';
    frame.focus();
    frame.print();
    This same thing is working fine in other browser but for IE is just not invoking the print dialog.
    Also I tried to get the frame.print(); on load of the frame but even that is not working exactly as that way it print the parent window in output.
    Few things I tried like:
    1) div.innerHTML = '<iframe src="' + urlValue + '"
    onload="this.contentWindow.print();"></iframe>';
    2) frame.contentWindow.focus();
    frame.contentWindow.print();
    3) window.document.getElementsByTagName('iframe')['frame'].onload = (function () {
    frame.focus();
    frame.print();
    I need to get the print of only the content which is in Iframe which I am binding in "printerDiv" by javascript.
    Any perfect/different solution from which I have tried then please post here?
    Thanks.

    PDF documents are hosted in an ActiveX or netscape plugin control which have their own printing functions.
    Start>Adobe Reader>Edit>Preferences - to adjust what functionality the PDF document viewer addon displays (menus etc).
    Tools>Manage Addons>Show all addons
    make sure you have both the x86 and x64 versions of your PDF reader Active X control installed and enabled. I would recommend also that you update to the latest version of the vendors' (Adobe?) plugin.
    Possibly you have disabled scripting of ActiveX controls in the IE security zone that your parent page maps to. Also there is an IE security zone feature that prevents navigation to a domain in a zone of lower integrity.
    Tools>Internet Options>Security tab, click "Reset all zones to default".
    when asking developer related questions it is helpful if you can include a link to your website.
    Rob^_^

  • Control key

    Hi, all ,
    I had certain queries which need to be clarified ,given below-
    1)Apart from controlling operations, what r the other purpose of control key??
    2) What is key figures and what is it function?
    3)In calibration order, is it required to do TECO by IW32 or can it be done by t-code QA32 itself???
    4)Through configuration can maintenance order screen be changed like notification ?
    5)To get PM standard report like MCI7 etc, what is required to be  done in configuration??
    6) How many activity types can be assigned to maintenance work center??
    7)Is work clearance management to be taken as separate package or in standard PM module itself it can be addressed??
    I will be gratefull to all of you as these are of my some doubts.
    thanks in advance
    rgds
    rajib
    Please read the rules of engagement before posting:
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement
    - Only One Question Per Posting
    You will get a better response if you stick to a specific functional area in each post. Your post covers a wide range of topics. I am going to lock this thread now.
    Regards
    Paul
    (Moderator)
    Edited by: Paul Meehan on Sep 17, 2008 4:07 PM

    well I orignally had it set to keylistener problem is that it only works when what ever component the keylistener is set to so if the keylistener is on the frame then it works as long as the frame has focus yet when I have a text box or a button or some other component has focus then the control key stops listening? I am using JInternalFrame I tried to add keylistener to the rootpane so that it was global but that doesnt seem to work either

  • How to handle text of iframe to send to remote printer in client side?

    Hello everybody,
    I am having problem to handle the printing text of iframe to send to remote printer. I am using JDK 1.5, JSP and JBOSS. My clients have to print the information displayed in iframe to their remote Printer. I am using javascript code below to print:
    /* CODE IS IN JAVASCRIPT */
         document.frames[frameName].focus();
         document.frames[frameName].print(); But the main problem is that it takes a lot of times about 2 mins. Why is the above code taking so long time? Is it due to javascript code or the printing process? Is there any method or function to send printing text of iframe to printer faster?
    can anyone help me to solve this problem.....
    Thank You.
    Edited by: ritesh163 on Aug 20, 2008 2:45 PM

    ritesh163 wrote:
    Hello stevejluke,
    I am seeking for the suggestion whether it can be done through javascript or there is any other function or method in JSP that can replay javascript code and also work faster.
    Thank you.But JSP has nothing to do with it. JSP lives on the server, not the client. If can't control the client printer, can't know about it, and can't print to it. This is purely client-side, which means not JSP.

Maybe you are looking for

  • Very slow DFSR on Windows Server 2008

    We need to have distributed file system between two location. I evaluating possibility to use DFS and two Windows Server 2008 to do it. I set up two computer with clean installation of system. The test is on two local subnets, so speed should not be

  • How to put safari in full screen mode by default ?

    Hello, my question is in the title... Thanks for any answer.

  • Why can't Apple give us some feedback re blank purchased app screen

    There have been numerous complaints about purchased apps not being able to be downloaded due to blank screen. WHY CAN'T APPLE PROVIDE SOME FEEDBACK????

  • Table only showing some borders

    HI, I'm new to dreamweaver although have mucked around a bit with MX. I now have CS3 and I'm going crazy over this one problem. ( at the moment anyway) I have a table with 3 rows and 3 columns. A lovely double border shows around each cell in design

  • PO price changes before the complete delivery

    I have an issue..... we have ordered a certain material say 2000 pcs  to be delivered over 6 months of time in a PO. The price at the tme of PO date was say 100 INR....now we have GRNd 200 pcs. After 1 month the vendor will charge 105 INR for the sam