Popups, focus, and J2SDK 1.4.2

Hi,
I have a program that draws a cartoon of a physical device in a JPanel and monitors mouse position, movement and left-clicks on the cartoon. When the user clicks a particular region of the cartoon, a popup containing a JTextField is displayed and given the focus, allowing the user to change the label for that part of the cartoon.
All this works fine with every 1.4.1 SDK that I've tried. However, if I run the program under any 1.4.2 release, odd things happen. At first, things appear to work normally, but if the program displays a modal dialog like a JFileChooser or a JOptionPane, then dismisses the dialog, a JTextField in the popup that is brought up where the dialog appeared can no longer be given the focus. The problem appears to be associated with the region of the screen where the dialog appeared, not the window position since you can move the program window to a different location and the program will appear to work normally. Move it back to its original position and the "dead" area where the dialog was displayed still won't accept focus.
I've simplified the original program substantially and can reproduce it with the program listed below.
* FocusProblem.java
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.*;
* Illustrate problem with obtaining focus after overlaying panel with
* a dialog.
public final class FocusProblem extends JFrame {
    private boolean editing;    // is the editor displayed or not
    private int xPos;           // mouse positions from mouse events
    private int yPos;
    private final JTextField chpEd;
    private final JPanel buttonPanel;
    private final JPanel clickPanel;
    private final JButton theButton;
    private Popup popup;
    private final PopupFactory factory = PopupFactory.getSharedInstance();
    public FocusProblem() {
        editing = false;
        xPos = yPos = -1;
        addWindowListener(new WindowAdapter() {
            public void windowClosing(final WindowEvent evt) {
                exitForm(evt);
        clickPanel = new JPanel();
        clickPanel.setPreferredSize(new Dimension(600, 400));
        getContentPane().add(clickPanel, BorderLayout.CENTER);
        theButton = new JButton("Show Dialog");
        theButton.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
                theButtonActionPerformed(evt);
        buttonPanel = new JPanel();
        buttonPanel.setBorder(new EtchedBorder());
        buttonPanel.add(theButton);
        getContentPane().add(buttonPanel, BorderLayout.EAST);
        pack();
        chpEd = new JTextField(10);
        // set up the mouse listeners
        final MyListener myListener = new MyListener();
        clickPanel.addMouseListener(myListener);
        clickPanel.addMouseMotionListener(myListener);
     * Handle a click on the button.
     * @param evt Not used.
    private void theButtonActionPerformed(final ActionEvent evt) {
        JOptionPane.showMessageDialog(this, "Just for testing", "A Modal Dialog",
                JOptionPane.INFORMATION_MESSAGE);
     * Handle a click on the close decoration.
     * @param evt Not used.
    private static void exitForm(final WindowEvent evt) {
        System.exit(0);
    // Editor related methods.
     * Bring up the <code>JTextField</code> over the panel where clicked.
     * Highlight the contents of the test field.
    private void bringUpEditor() {
        editing = true;
        clickPanel.setToolTipText(null);
        chpEd.setText("X = " + xPos + ", Y = " + yPos);
        final Point p = new Point(xPos, yPos);
        // getPopup expects screen coordinates, so do the conversion
        SwingUtilities.convertPointToScreen(p, this);
        popup = factory.getPopup(clickPanel, chpEd, p.x, p.y);
        popup.show();
        chpEd.setVisible(true);
        if (chpEd.requestFocusInWindow() != true) {
            System.out.println("Failed to obtain focus");
//        chpEd.requestFocus();
//        chpEd.grabFocus();
        chpEd.getCaret().setDot(0);
        chpEd.getCaret().moveDot(chpEd.getText().length());
     * Hide the editor and set <code>editing</code>
     * to <code>false</code>.
    private void takeDownEditor() {
        popup.hide();
        popup = null;
        editing = false;
    // MouseInputAdapter methods
    final class MyListener extends MouseInputAdapter {
         * Watch mouse clicks on the panel. If the global variable
         * <code>editing</code> is <code>true</code>, the click occurred
         * outside of the editor, so any changes in the editor are
         * accepted and the editor is take down. If <code>editing</code>
         * is <code>false</code>, start editing at the position of the click.
         * @param e The <code>MouseEvent</code> to be responded to. Used
         * to retrieve the mouse position.
        public void mousePressed(final MouseEvent e) {
            if (editing) {
                takeDownEditor();
            } else {
                xPos = e.getX();
                yPos = e.getY();
                bringUpEditor();
         * Watch for mouse moves. If the global variable <code>editing</code>
         * is <code>false</code>, set the text of the panel's tooltip to the
         * mouse location.
         * @param e The <code>MouseEvent</code> to be responded to. Used to
         * retrieve the mouse position.
        public void mouseMoved(final MouseEvent e) {
            if (!editing) {
                xPos = e.getX();
                yPos = e.getY();
                clickPanel.setToolTipText("X = " + xPos + ", Y = " + yPos);
     * A program entry point to run the test.
     * @param args Not used.
    public static void main(final String[] args) {
        new FocusProblem().show();
}To observe the problem:
1. Start the program and allow the mouse to hover near the center of the left panel. A tooltip should appear with the position of the mouse.
2. Click and a popup with an editor should be brought up. The JTextField should have the focus. Click somewhere else to dismiss the editor.
3. Click the button in the right pane to display a dialog. over a region of the left panel. Dismiss the dialog.
4. Click in the area where the dialog was displayed. If running 1.4.1, the JTextField will be focused, just as in step 2. If running 1.4.2, the popup will appear with the JTextField but will not have foucs and will not accept focus by clicking (or any other method I've been able to find.)
I've observed this problem with Linux (Redhat 9), Windows 98, Win2K, and WinXP on PIII and P4's. The problem occurs with J2SDK 1.4.1 and 1.4.2_01.
I posted this as a bug right after 1.4.2 came out, but have only received the usual automated reply from Sun. Can't find it in the bug database. Am I missing something or is this really a bug? Any workarounds?
Other Weirdness
I've also noticed that if you run the program and let the mouse hover long enough for the tooltip to appear, then move the mouse down so that the tooltip appears to "touch" the bottom border, the tooltip will begin to flicker a lot when you move the mouse around higher in the window when running 1.4.2. Doesn't happen with any J2SDK 1.4.1 release that I've tried. Is this another manifestation of the problem described above?
Thanks in advance for all the help.

I'm wondering if you've been able to reconcile the problem. I have exactly the same situation. I've tried everything I could think of, but whenever I call popup.show() followed by a call to requestFocusInWindow,
I get a false return - meaning of course the popup (or more precisely a JList in the popup) can NOT receive the focus. Same behavior as yours. I really liked the way it worked under 1.4.1 and hate to give it up. Surely hope you've figured it out and can share with me.

Similar Messages

  • Keep focus and actionlistener

    I open as a popup a custom JPanel but
    I want to keep focus and actionlistener on it
    while it is opened.
    is there a way?
    thanks for any clue

    I tried removing all the pattern validations on the field and added this below code in the validate event of the text field and it works..
    var strCode;
    var f = /^([A-Z]{2}[1-9]{5}[A-Z])$/;
    if(this.rawValue != null && String(this.rawValue) != "") {
                        strCode = String(this.rawValue);
                        if (f.test(strCode) == false) {
                                            xfa.host.messageBox("Invalid pattern!");
                                            xfa.host.resetData();
                                            xfa.host.setFocus(this);
    xfa.host.setFocus(this);

  • Camera Raw loses system focus and becomes inactive

    While working in ACR if I hover over any of the command buttons, Save Image,  Open Image, Cancel, or Done for a few seconds the "tool tip" for the button displays and as soon as I move the mouse again the whole Camera Raw windows loses system focus and becomes inactive (every tab, control, menu, etc., becomes greyed out).  To regain the system focus I must move the mouse to the windows 7 taskbar and then back into Camera Raw.  If the fullscreen checkbox in Camera Raw is active the only way to regain system focus is to press the Windows Key twice on the keyboard and move the mouse out of the taskbar tray.  This gets pretty frustrating.  Any clues?

    It doesn't normally do this, I can assure you.  Normally the tooltips just pop up and Camera Raw stays active.
    Do you have any desktop management software installed, besides what Windows provides?
    Are your video drivers up to date?
    -Noel

  • How to focus and select to the next cell with a ListView when scrolling?

    I have a ListView filled with cells and I'd like to scroll to the next cell to have it focused and selected.
    My code works to scroll down but the scroll bar is going to far!
    How can I reduce the scroll size to each cell, so I can see the focused cell? Is there a better way to implements this?
    Here is my code:
    documentListView.scrollTo(0);
    documentListView.getSelectionModel().select(0);
    int indexSize = documentListView.getItems().size();
    for (Node node : documentListView.lookupAll(".scroll-bar")) {
      if (node instanceof ScrollBar) {
      final ScrollBar bar = (ScrollBar) node;
      bar.valueProperty().addListener(new ChangeListener<Number>() {
      @Override
      public void changed(ObservableValue<? extends Number> value, Number oldValue, Number newValue) {
      int selectedIndex = documentListView.getSelectionModel().getSelectedIndex();
      if(selectedIndex <= indexSize && listScrollDown(oldValue.floatValue(), newValue.floatValue())) {
         selectedIndex++;
         documentListView.scrollTo(selectedIndex);
         documentListView.getFocusModel().focus(selectedIndex);
         documentListView.getSelectionModel().select(selectedIndex);
    Thanks for your help,
    Regards

    You could set the IsHitTestVisible property of the WebControl to false but then you won be able to interact with the web page:
    <awe:WebControl ... IsHitTestVisible="False"/>
    Another better option would be to handle the PreviewMouseLeftButtonDown of the WebControl, find the ListBoxItem in the visual tree and then set its IsSelected property like this:
    <ListView x:Name="BrowserListview" ItemsSource="{Binding browserCollection}">
    <ListView.ItemTemplate>
    <DataTemplate>
    <VirtualizingStackPanel Orientation="Horizontal">
    <awe:WebControl Source="{Binding mySource}" PreviewMouseLeftButtonDown="wc_MouseLeftButtonDown"/>
    <Rectangle/>
    </VirtualizingStackPanel>
    </DataTemplate>
    </ListView.ItemTemplate>
    </ListView>
    private void wc_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
    ListViewItem lbi = FindParent<ListViewItem>(sender as DependencyObject);
    BrowserListview.UnselectAll();
    lbi.IsSelected = true;
    private static T FindParent<T>(DependencyObject dependencyObject) where T : DependencyObject {
    var parent = VisualTreeHelper.GetParent(dependencyObject);
    if (parent == null) return null;
    var parentT = parent as T;
    return parentT ?? FindParent<T>(parent);
    Hope that helps.
    Please remember to close your threads by marking helpful posts as answer.

  • I opened a website that said that all of my files had been encrypted. A popup appeared and asked if I wanted to leave the page, but when I tried to, it wouldn't let me.  How do I know if this is a real problem or not?

    I was researching information for a class and I clicked on a website that said that all of my files had been encrypted.  A popup appeared and asked if I wanted to leave the page but when I tried to, it would let me.  I had to force quit Safari in order to do so.  How do I know if this is a real problem or not? 

    It's a JavaScript scam that only affects your web browser, and only temporarily.
    1. Some of those scam pages can be dismissed very easily. Press command-W to close the tab or window. A huge box will pop up. Press the return key and both the box and the page will close. If that doesn't happen, continue.
    2. From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Security
    and uncheck the box marked Enable JavaScript. Leave the preferences dialog open.
    Close the malicious window or tab.
    Re-enable JavaScript and close the preferences dialog.
    3. If the Preferences menu item is grayed out, quit Safari. Force quit if necessary. Relaunch it by holding down the shift key and clicking its icon in the Dock. From the menu bar, select
              Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    to get rid of any cookies or other data left by the server. Open your Downloads folder and delete anything you don't recognize.

  • Popup page and PREV_PAGE

    Can you set a call to a popup to pass the page number of the calling page to the PREV_PAGE field of the popup page and then set the closing process on the popup page to go back to &PREV_PAGE. instead of a page number? What would be the syntax for such a thing?

    Below is the code I am now using. You will notice that it includes specific pages:
    Calling page calls up p 127, the popup page:
    <input type="button" value="Add Call Administrators" onClick="javascript:window.open('f?p=&APP_ID.:127:&APP_SESSION.:::','Popup2','width=400,height=300')";>
    Popup page closing process, sends back to P36(calling page):
    BEGIN
    -- Redirects the calling (parent page) to the Allocate Site to Run
    --page
    -- then closes this popup window
    htp.p('<body>');
    htp.p('<script type="text/javascript">');
    htp.p('window.opener.location.href="f?p=&APP_ID.:36:&SESSION.";');
    htp.p('window.close(this);');
    htp.p('</script>');
    htp.p('</body>');
    END;
    What I want to do is be able to put something in the calling page code to insert the page number of the calling page into P127_PREV_PAGE, and then to replace 36 with &P127_PREV_PAGE. I just don't know where or how to insert them into the code.
    If I do not have a page number in the closing process, it bounces to the previous page and then bounces to the login page.

  • Difference between fixed focus and auto focus?

    what is difference between fixed focus and auto focus and which is better?

    Thanks for the advice Phonehacker, this Forum is so helpful on a variety of subjects, and the users are so patient, that's why I enjoy it so much   My diet is now perfectly organised and my larder is full of Brown Bread and Red Wine 
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • Gainer Focus and Lost Focus

    How implements the methods to gainer focus and lost focus?
    Thanks

    Use a node.focusedProperty() change listener to know when a field gains or loses focus.
    Call node.requestFocus() to ask for focus (for some reason I have to wrap this in Platform.runLater to get it to actually do anything).
    Call node.setFocusTraversable(false) if you don't want the user to be able to tab to the node, but still be able to click on the node to give it focus.
    Call node.setDisable(true) if you don't want the node to be focusable at all.
    I'm not sure how the focus traversable order is calculated, perhaps the order that items are added to the scene?
    Not sure how you would create a custom focus traverse if you needed one.
      @Override public void start(Stage primaryStage) {
        final TextField tf1 = new TextField("First but not initially focused");
        final TextField tf2 = new TextField("Second initially focused");
        Platform.runLater(new Runnable() { public void run() { tf2.requestFocus(); } });
        final TextField tf3 = new TextField("Can focus by clicking on, but not by tabbing to.");
        tf3.setFocusTraversable(false);
        final TextField tf4 = new TextField("Cannot focus at all.");
        tf4.setDisable(true);
        tf1.focusedProperty().addListener(new ChangeListener<Boolean>() {
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
              if (newValue) {
                System.out.println("First text field gained focus");
              } else {
                System.out.println("First text field lost focus");
        VBox root = new VBox(); root.setSpacing(5);
        root.getChildren().addAll(tf1, tf2, tf3, tf4);
        primaryStage.setScene(new Scene(root, 300, 100));
        primaryStage.show();
      }

  • The jpegs in my movie start in focus then quickly go out of focus, and then come back to focus just as the clip ends

    The jpegs in my movie start in focus then quickly go out of focus, and then come back to focus just as the clip ends

    Viewed in FCP or after export?
    Russ

  • Camera focusing and resolution.

    Camera doesn't seem to focus and takes poor pictures.  what is wrong?

    iPad has a very low resolution camera for still pictures. It is not really meant to be used as a camera, more for video confrencing. For focusing you need to tap on the area you want clear and be careful not to move.

  • Close popup window and refresh the parent window

    Hello,
    I have a button in a normal report, when clicked opens up an popup window which is a form containing some items and here in this form (i have some editable text items) I make some changes and click on the apply changes button -- this should update the form, close the popup window and should refresh the parent window.
    can anyone please help me out with this issue.
    Thanks,
    Orton

    you have your popup window. When they apply the changes you want it to close the window, right?
    Modify the button (save, apply changes) and give it url redirect to the custom function you create (See below): javascript:saveChanges();
    in the page header, add a new function:
    <script type="text/javascript">
    function saveChanges(){
         doSubmit('SAVE');//this is the line to save the current form on the popup window. (This assumes SAVE is the request value that should udpate the db)
         window.close();//close the popup window
         window.opener.doSubmit('REFRESH');//call doSubmit function on the parent window to cause the page to refresh.
    </script>

  • Popup window and navigate to home page visual web part SP 2013

    I've a visual webpart where i am inserting items in the list in the button click event as below
    protected void btnSubmit_Click(object sender, EventArgs e)
    SPSite site = new SPSite(SPContext.Current.Site.OpenWeb().Url);
    SPWeb web = site.OpenWeb();
    SPList list = web.Lists["Request"];
    SPListItem item = list.Items.Add();
    item["Title"] = txtBoxTitle.Text;
    item.Update();
    Now after items is being added in the list i want to show popup window with message showing that
    "item has been inserted and click here to go to home page of the site"
    how do i achieve this can anyone help in this
    Note:there is a restriction in our requirement so only sandboxed solution can be used so i want resolution for sandboxed solution 

    You can' t use criptManager.RegisterStartupScript for redirection in sandbox solution.
    Please find the below reference
    http://social.msdn.microsoft.com/Forums/office/en-US/bd37b640-e225-41c0-8344-9f3b52fe0434/open-popup-window-and-redirect-user-to-home-page-in-sandboxed-solution?forum=sharepointdevelopment
    You have one more option to open a popup SP.UI.ModalDialog
    Please find the below reference
    http://msdn.microsoft.com/en-us/library/ff798375.aspx
    http://blogs.msdn.com/b/chaks/archive/2011/09/14/modal-dialog-box-in-sharepoint-sandbox.aspx

  • IPhone 4 keeps focusing and refocusing in video

    When shooting video with my iPhone 4, the image keeps focusing and refocusing as I move the camera causing the picture to pop in and out of focus. It's happening in all video apps so I'm suspecting the phone.
    Ideas?

    Basic troubleshooting steps clearly outlined in the User Guide are restart, resest, restore from backup, restore as new.
    If you still have problems after going through ALL the recommended troubleshooting steps, then you likely have a hardware issue.  You'll need to bring your phone into Apple for evaluation.

  • JS: Get Control that has the Focus and paste something into it

    Hi,
    I want to implement some clientside code that gets the control that has the focus and copy some text into it.
    Can this be easily accomplished?
    Thanks
    Sven

    Hi,
    According to your post, my understanding is that you want to get the focus element via JavaScript.
    We can use the document.activeElement to get the current active element.
    http://stackoverflow.com/questions/497094/how-do-i-find-out-which-dom-element-has-the-focus
    http://stackoverflow.com/questions/11277989/how-to-get-the-focused-element-with-jquery
    Then you can use the obtained focus element to paste text into it.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
    Jason Guo
    TechNet Community Support

  • How to set focus and mark red on certain select option field

    hi experts
    I embedded a select_option view in my application and  tried to use IF_WD_SELECT_OPTIONS->request_focus to set focus on a certain select option field if the logical check failed, and also hope the low field of the select option can be marked red....but things does not happen that way....
    could anyone kindly tell me how to implement that requirement?
    tkx and regards
    sun

    What is the problem you are facing in this ?
    Requesting focus is easy.
    just call the method request focus and pass the id of the parameter whose lower value field you want to focus.
    as shown below.
    code you might have written in wddoinit
    DATA: LT_RANGE_TABLE TYPE REF TO DATA,
            RT_RANGE_TABLE TYPE REF TO DATA,
            READ_ONLY TYPE ABAP_BOOL,
            TYPENAME TYPE STRING.
        DATA: LR_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER,
            L_REF_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.
    *   * create the used component
      L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_SELECT_OPTIONS( ).
      IF L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
        L_REF_CMP_USAGE->CREATE_COMPONENT( ).
      ENDIF.
        WD_THIS->M_WD_SELECT_OPTIONS = WD_THIS->WD_CPIFC_SELECT_OPTIONS( ).
        WD_THIS->M_HANDLER = WD_THIS->M_WD_SELECT_OPTIONS->INIT_SELECTION_SCREEN( ).
    LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'ZDEALERID' ).
    * * add a new field to the selection
      WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'ID'
      IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = READ_ONLY ).
    code for focusing a field.
    wd_this->m_handler->request_focus( i_id = 'ID' ).
    you must have declared attributes m_handler and m_wd_select_options type reffering to IF_WD_SELECT_OPTIONS and
    IWCI_WDR_SELECT_OPTIONS respectively.
    and regarding that red color i am not sure it is possible without using message manager.
    thanks
    sarbjeet

Maybe you are looking for

  • How to export data from a string to a CSV file

    Hello, i do have a string in a Livecycle Designer script object with a couple of rows with different entries divided by a semicolon: COLUMN1;COLUMN2;COLUMN3 Entry1;Entry2;Entry3 Entry4;Entry5;Entry6 The goal is now to export this string from Livecycl

  • Extended rights Acrobat 9.0 forms

    I would like to enable voluntary community groups completing the application forms that I've created using Acrobat 9 Professional to be able to save the forms and complete them at their leisure rather than having to complete the form in one go.  Is t

  • White border around pasted images

    This is probably a very simple problem, I could just fix it by restoring default settings, but I'd like to know how to do it manully. Basically whenever I copy & paste an image, a white border is created around that pic. Usually it's just the selecti

  • How to create an index from more than one pages document?

    I have 10 different pages documents. Each document is a book chapter. Now I would like to create one index for all of these chapters in a new pages-file without copying all files into one single file. How does this work?

  • Enhancing Enterprise Service - Input Message Enhancement

    Hi I am using a standard Enterprise Service and have successfully Enhanced the Output Message (Created a Data Type Enhancement in PI), did the BADI Implementation and mapped the Outgoing Response in Outbound Processing of BADI Implementation and able