Request Focus in JInternalFrame

Hello,
I'd like to keep the focus of an JInternalFrame, even if the user clicks on any other frame inside of the desktop. That way he should be "forced" to complete the actual window before switching to another one. Something like IsAlwaysOnTop and HasAlwaysFocus ;-)
I've already tried requestFocusInWindow, but it doesn't work...
thanks,
Matthias

Hmm... try FocusAdapter and the method focusLost(FocusEvent e). In the focusLost, call requestFocus() for the JInternalFrame. Maybe not a nice solution, but one that could work...
Tell me if it worked

Similar Messages

  • Problem with requesting focus for a list

    Hi there !
    What would be the right way to request focus for a list component ?
    I can use select() method to select some item from a list, but the list itself still hasn't got a focus until I click it.
    What I'd like to do is to be able to highlight some item from the list by using up and down arrow keys only, without clicking the list first =)

    The list is visible, but still this doesn't work.
    I think that the reason for this may be that I'm running this app on Nokia 9210 Communicator emulator. The emulator itself has had some not-so-minor problems...

  • Requesting focus for JTextField inside JPanel

    I have an application with following containment hierarchy.
    JFrame --> JSplitPane --> JPanel.
    JPanel is itself a seperate class in a seperate file. I want to give focus to one of the JTextfields in JPanel, when the JPanel is intially loaded in the JFrame. I believe that I cannot request focus until the JPanel is constructed. I can set the focus from JFrame (which loads JPanel) but I want to do this from JPanel. Is there any technique to request focus from the JPanel itself (preferably during JPanel construction).
    regards,
    Nirvan.

    I believe that I cannot request focus until the JPanel is constructedYou can't request focus until the frame containing the panel is visible. You can use a WindowListener and handle the windowOpened event.

  • Request focus for message area

    Dear All,
    As my screen is long hence if an error comes we will require to scroll down so I have added a message area UI element and in do modify method of the view i have request focus to my message area but it is not working.  Below is the code which I have written:
    try{
              IWDMessageArea msgarea=(MessageArea)view.getElement("MessageArea");
            msgarea.requestFocus();
            catch(Exception e)
    Is there any other property or changes need to be made.
    Thankyou.
    Regards,
    Santosh

    Hi,
    In would say, create an input field at the top left corner of the screen. Set its width to zero and bind it to a context attribute say Va_ShowMesg of type string. Now insert a MessageArea UI element just below the inputfield to display all the erro message at the top left.
    Now if you request focus for the input field using the following code, the focus will automatically come to the Message Area as well.
    wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(),wdContext.getNodeInfo().getAttribute(
              wdContext.currentContextElement().VA__SHOW_MESG));
    You can call this code whenever you need to display message to user in the message area and shift focus of the screen to the message displayed.
    Regards,
    Tushar Sinha

  • JDialog and request focus

    Hi
    I am designing an application that brings up a JDialog box. When a button is pressed on this JDialog box this triggers an action event and some code is executed.
    When this button is pressed I dispose the dialog box and I want the focus to change to one of my components, I have been doing this with the requestFocus command. For some reason this focused event is not picked up by the focus handler. This only happens in this one place, if I move the requestFocus code to anywhere else in the program the focus event works fine. Does anyone have any ideas why.
    Thanks

    Without seeing any code, I would guess that disposing of a dialog causes focus changes to be requested internally. So if you put your focus change request after you dispose the dialog, that might help.

  • Cell request focus problem

    Hi,
    I have jtable with two column. Column A and column B. I type string "stupid" in column A. Then when I change the cell by pressing Enter or right arror or other arrow, it suddenly check the value in column A with the string "clever". Then it is not same. So my Jtable put focus in that cell again and hightlight the string "stupid" so when user type something, the string "stupid" is cleared and replaced by whatever the user typed. The user is forced to type string "clever" otherwise he cann't go anywhere.
    How do I do that? ( put focus on certain cell and hightlight the string )
    I don't know how to hightlight but this is how I try to give the focus to that cell:
    JTable.getModel().addTableModelListener( new TableModelListener() {
        public void tableChanged(TableModelEvent tme) {
            final int column = tme.getColumn();
            final int row = tme.getFirstRow();
            if(column==0) {
                try {
                    if((String)JTable.getValueAt(row,column)!="clever") {
                            JTable.setEditCell(row,column);
                catch( SQLException e ) {
                    e.printStackTrace();
    });With this code, I looked up in that cell. Cann't do anything. Cann't push the button. I just have to kill it by operating system.
    Thank you.

    A TableModelListener listens for changes that have already been made to the table, so you should not be doing error checking here.
    Here is one way (I don't know if its the best) that allows you to do some error checking:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class TableEdit extends JFrame
         TableEdit()
              JTable table = new JTable(5,5)
                   public void changeSelection(int row, int column, boolean toggle, boolean extend)
                        if (! isEditing())
                             super.changeSelection(row, column, toggle, extend);
                        else
                             DefaultCellEditor editor = (DefaultCellEditor)getCellEditor();
                             editor.getComponent().requestFocusInWindow();
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JScrollPane scrollpane = new JScrollPane(table);
              getContentPane().add(scrollpane);
              //  Use a custom editor
              TableCellEditor fce = new FiveCharacterEditor();
              table.setDefaultEditor(Object.class, fce);
         class FiveCharacterEditor extends DefaultCellEditor
              FiveCharacterEditor()
                   super( new JTextField() );
                   ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
              public boolean stopCellEditing()
                   try
                        String editingValue = (String)getCellEditorValue();
                        if(editingValue.length() != 5)
                             ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
                             getComponent().requestFocusInWindow();
                             JOptionPane.showMessageDialog(
                                  null,
                                  "Please enter string with 5 letters.",
                                  "Alert!",JOptionPane.ERROR_MESSAGE);
                             return false;
                   catch(ClassCastException exception)
                        return false;
                   return super.stopCellEditing();
              public Component getTableCellEditorComponent(
                   JTable table, Object value, boolean isSelected, int row, int column)
                   Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column);
                   ((JComponent)c).setBorder(new LineBorder(Color.black));
                   return c;
         public static void main(String [] args)
              JFrame frame = new TableEdit();
              frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Requesting focus to a component

    Hi All,
    I got some JTextFields in a JDialog derived class to enter user information and one button. If the button is clicked without entering information in the JTextFields, a message box is displayed using JOptionPane.showMessageDialog.
    I want to change the focus to the first JTextField once the messagedialog box is disposed. How can I do it?
    Thanks
    roger

    Hi aswath,
    I called the message box from my JDialog derived class like this.
    javax.swing.JOptionPane.showMessageDialog(this,
    "", "", javax.swing.JOptionPane.ERROR_MESSAGE);
    this.m_jTextField.requestFocus();
    After that I called requestFocus().
    When I called the requestFocus the messagebox showed is the active window.
    But it is not working. Can anybody help?
    roger

  • Request focus on view element

    Hi everybody,
    I have a little problem and I didn't know how to solve it. I'd like to set the cursor at any input field at my view.
    I tried this like this way:
      DATA: lr_elem TYPE REF TO if_wd_view_element.
      lr_elem = view->get_element( gv_cursor ).
      view->request_focus_on_view_elem( lr_elem ).
    If I start the webdynpro the cursor was set at the right position...now if I press enter or a button at the dynpro the program logic will be done and the method WDDOMODIFYVIEW will be processed again...but the cursor were not set at any field at the dynpro, why?

    The following works in SP10.
    I cant see what you have missed:
    My test was 2 buttons, each button changes the focus to a different input field.
    Attribute called FIELD was declared.
    method WDDOMODIFYVIEW .
      DATA: lr_elem TYPE REF TO if_wd_view_element.
    lr_elem = view->get_element( wd_this->field ).
    if lr_elem is BOUND.
    view->request_focus_on_view_elem( lr_elem ).
    endif.
    endmethod.
    method ONACTIONSET_F1 .
      wd_this->field = 'F1'.
    endmethod.
    method ONACTIONSET_F2 .
      wd_this->field = 'F2'.
    endmethod.
    regards
    Phil

  • How to request focus for Panel hiding behind another panel?

    Hi guys,
    I have two panels(of different sizes) within a JFrame, i have one button (in smaller panel)that does some query in the back end & populates the results in another panel (bigger panel), now assuming that i am in smaller panel, how is that i can bring up the bigger panel that is hiding behind this smaller panel.
    I tried using requestFocus method but its not working.
    Can anyone help me in this regard?
    Thanks & Regards,
    Vishal

    Thanks for your feedback, but i am not using card layout instead i am using a Grid bag layout, i dont see any method like next() or show() for a instance of GridbagLayout.
    Any other alternative?
    Thanks & Regards,
    Vishal

  • Problem gaining focus

    Hi all, Im writing an applicaiton and I'm having some trouble getting the focus where I want it and was wondering if anyone could give me a suggestion.
    Here's the setup: I have a JFrame with a JToolBar on it. One of the buttons on the toolbar fires an extention of PAction that I setup. This PAction brings up a JInternalFrame with an optionpane on it that allows the user to enter/edit several pieces of info (several JTextComponents). On this InternalFrame is an InternalFrameListener, on its internalFrameActivated event I do a requestFocus() on the first JTextComponent on the InternalFrame.
    Whats currently happening is that the internalframe is activating and being selected, but the focus seems to be remaining on the toolbar's button. If I fire the same action using a method other than the toolbar (like the menu), the focus goes exactly where I want it.
    Here's what I know so far from debugging:
    1) The listener is definetly firing.
    2) The component never gains focus (in otherwords, im not loosing it after the request)
    3) There is a thread running but it's sleeping until the ok or cancel button is pressed.
    Here's what I've tried so far:
    1) Removing the thread
    2) Requesting focus on the first component: after the frame is opened, after the frame is activated, at the end of the PAction, and having the action reselect the internalframe then give the component focus
    3) I verified there are no other action listeners on the button.
    4) Stared blankly at my screen for a long time lost in thought.
    Any help will be very appreciated,
    Kris

    I experienced the same problem and the way I resolved it
    was making the toolbar buttons non-focusable.
    But this may not be good for you if you need to navigate the
    toolbar with the keyboard.

  • JComboBox.setPopupVisible() and focus

    Hello,
    the following code demonstrates that always when the combobox is editable and the standard focus sequence is modified, a setPopupVisible(true) indeed opens the popup, but it is immediately closed again. Is anything wrong with the code?
    Although there are quite a number of JComboBox bugs in the database, I did not find this one. If it is a bug, of course I would be interested in a workaround.
    Regards
    J�rg
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Y extends JFrame
      private JComboBox cmb;
      public Y()
      { setSize(300,300);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container cp= getContentPane();
        cp.setLayout(null);
        final JCheckBox cb= new JCheckBox("Combo editable");
        cb.setBounds(80,30,130,20);
        cb.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
         cmb.setEditable(cb.isSelected());
        final JTextField tf1= new JTextField();
        tf1.setBounds(50,60,60,20);
        tf1.addFocusListener(new FocusAdapter() {
          public void focusLost(FocusEvent evt) {
         if (!tf1.getText().equals("ee")) {
           cmb.requestFocusInWindow(); // Prevents popup to stay open.
           cmb.setPopupVisible(true);
           System.out.println(cmb.isVisible());
        JTextField tf2= new JTextField();
        tf2.setBounds(150,60,60,20);
        tf2.addFocusListener(new FocusAdapter() {
          public void focusLost(FocusEvent evt) {
         cmb.setPopupVisible(true);
        cmb = new JComboBox(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"});
        cmb.setBounds(100,90,50,20);
        cmb.setSelectedIndex(-1);
        System.out.println("LightWeight: "+cmb.isLightWeightPopupEnabled());
        cp.add(cb);
        cp.add(tf1);
        cp.add(tf2);
        cp.add(cmb);
        setVisible(true);
        tf1.requestFocusInWindow();
      public static void main(String args[])
      { java.awt.EventQueue.invokeLater(new Runnable()
        { public void run()
          { new Y();
    }

    Well, there's two things I note. The first is you're printing out the comboBox's visible status, which is always true, when you're probably trying to get the comboBox's popup's visible status.
    The second thing is the cause of your problem. You request focus on the combo box. When it is editable, however, it is the editor component that gets the focus, not the combo box. So, the popup is made visible and then the editor component loses focus because the combo box gets focus, and so the popup is hidden.
    This change does what you want, I think:
        tf1.addFocusListener(new FocusAdapter() {
          public void focusLost(FocusEvent evt) {
        if (!tf1.getText().equals("ee")) {
            if ( cmb.isEditable() )
                cmb.getEditor().getEditorComponent().requestFocusInWindow();
            else
                cmb.requestFocusInWindow(); // Prevents popup to stay open.
          cmb.setPopupVisible(true);
          System.out.println(cmb.isVisible());
        });

  • JTextField not gaining focus on initialization of Applet

    I originally tried posting this in the Applets forum but was unable to get a response, so I am re-posting here in hopes of finding an answer.
    I have a simple JApplet with a JFrame, a JTextField added to the JFrame, and a WindowListener added to the JFrame that requests focus to the JTextField whenever the JFrame is activated. Upon opening the applet the WindowListener's windowActivated() method is called and requestFocusInWindow() for the JTextField returns true however the focus is never actually given to the JTextField. According to the API for Component,
    "This method returns a boolean value. If false is returned, the request is guaranteed to fail. If true is returned, the request will succeed unless it is vetoed, or an extraordinary event, such as disposal of the Component's peer, occurs before the request can be granted by the native windowing system. Again, while a return value of true indicates that the request is likely to succeed, developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event"
    I am assuming that the request is getting "vetoed" but I don't understand why or what this even means. If I alt-tab off of the applet window and alt-tab back on then the request is handled properly. This issue only arises on initially opening the applet. Has anyone seen this issue before? Is there a known workaround? Here is the code for my sample applet:
    import javax.swing.*;
    import java.awt.event.*;
    public class MyApplet extends JApplet{
    private JFrame myFrame;
    private JTextField myTextField;
    private FrameWindowListener myListener;
    public void init(){
    myFrame = new JFrame();
    myFrame.setSize(700, 360);
    myFrame.setLocation(100, 100);
    myTextField = new JTextField();
    myFrame.add(myTextField);
    myListener = new FrameWindowListener();
    myFrame.addWindowListener(myListener);
    public void start(){
    myFrame.setVisible(true);
    myFrame.pack();
    public class FrameWindowListener extends WindowAdapter{
    public void windowActivated(WindowEvent e){
    boolean focus = myTextField.requestFocusInWindow();
    if(focus){
    System.out.println("Focus successful");
    } else{
    System.out.println("Focus unsuccessful");
    }

    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting
    Works fine for me using JDK1.4.2 on XP using appletviewer.
    The only suggestion I would make is that you should use pack() before setVisible(...). Also I usually have that code in the init() method instead of the start() method.

  • Accelerators, JTextField, and focus

    I created a JMenuItem for Save. I also created an accelerator for the Save menu item.
    JMenuItem saveItem;
    JMenu fileMenu = new JMenu ("File");
    fileMenu.add (saveItem = new JMenuItem ("Save"));
    saveItem.setMnemonic ('S');
    KeyStroke cntrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S,
    Event.CTRL_MASK);
    saveItem.setAccelerator (cntrlS);
    saveItem.addActionListener (new ActionListener() {
    public void actionPerformed (ActionEvent e) {
    doSaveNote();
    When the user is finished entering data into the JTextField(s), the user then either presses ctrl-S or clicks on the Save button on the menu. My code (not shown) validates data in JTextFields when the Save accelerator or button is pressed (blank field is considered invalid as well as wrong flight number). If data is invalid, then the first field with invalid data gets focus.
    If the JTextField has focus and invalid data is there, then when the user clicks the Save button the JTextField still has focus with a message letting the user know the data is invalid. However, if the user puts invalid data in the JTextField and uses the accelerator ctrl-S without tabbing out of the field first, the invalid JTextField does not get focus and no error message is presented. When using the accelerator the invalid JTextField only gets focus and prints an error message if the user tabs out of the JTextField befor pressing ctrl-S.
    I don't want to tab out of the field. Why is the behavior different between the accelerator and clicking the Save button? Any help is appreciated.

    You can request focus for another component.
    Or you could do: myTextField.setFocusable(false). But in this case you would have to make it fosucable later on if you want to use it.

  • JTable cell focus outline with row highlight

    With a JTable, when I click on a row, the row is highlighted and the cell clicked has a subtle outline showing which cell was clicked.
    I would like to do that programatically. I can highlight the row, but I have not been able to get the subtle outline on the cell. My purpose is to point the user to the row and cell where a search found a match. I do not have cell selection enabled, because I want the whole row highlighted.
    My basic code is:
    table.changeSelection(irow, icol, false, false);
    table.scrollRectToVisible(table.getCellRect(irow, icol, true));I keep thinking I just need to find a way to "set focus" to the cell so the subtle outline is displayed, but I cannot find something like that.
    Does anyone have some ideas on how to activate that automatic outline on the cell? I prefer not to write custom cell renderers for this if possible.

    That seems unnecessarily complicated, the outline is the focused cell highlight border so requesting focus on the table should be enough.
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    public class TestTableFocus {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    final JTable table = new JTable(10, 10);
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(new JScrollPane(table));
                    frame.getContentPane().add(new JButton(
                      new AbstractAction("Focus cell") {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            table.changeSelection(5, 5, false, false);
                            centerCell(table, 5, 5);
                            table.requestFocusInWindow();
                        private void centerCell(JTable table, int x, int y) {
                            Rectangle visible = table.getVisibleRect();
                            Rectangle cell = table.getCellRect(x, y, true);
                            cell.grow((visible.width - cell.width) / 2,
                                    (visible.height - cell.height) / 2);
                            table.scrollRectToVisible(cell);
                    }), BorderLayout.PAGE_END);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
    }

  • JComboBox focus working differently in different environ

    in our application we are requesting focus in a date JComboBox from many places, not all developers are doing it consistantly. What is the best way? We are in test now. Our testers run the Application with Web Start. Some on Windows 2000. Some on Windows XP. The ones on XP ( and an older version of Web Start than I have, v1.2) are seeing the focus go to the little arrow thingy instead of the text area of the combobox when the following line of code is used:
    protected void focusOnDateBeanSection() {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    getMyView().getDateBean().getJEffDateCBX().requestFocusInWindow();
    Any new thoughts on this, searching through older forums, found this:
    getJEffDateCBX().getEditor().getEditorComponent().requestFocusInWindow();
    why couldn't you just do this:
    getJEffDateCBX().getEditor().getTextField().requestFocusInWindow();
    and why not just .requestFocus() ?

    so I'm saying requestFocusInWindow isn't reliable accross platforms either. So should I :
    .getJEffDateCBX().getEditor().getEditorComponent().requestFocusInWindow();
    or
    getJEffDateCBX().getTextField().requestFocusInWindow();

Maybe you are looking for

  • AC3 with QT

    Hi, I AHVE QUTION IF CAN I MAKE QT MOVIE WITH AC3 FILE . i have qt movie file and ac3 file how can i make one qt movie with ac3 file can some help me please !!!! MASTER-DVD from ISRAEL

  • Disable Backspace when in input text fields

    Im trying to find a way to disable the keyboard backspace button from going back a page in the site but allowing it to function as a character delete when needed for typing in an input text field of a form. Strangely this problem only occurs for abou

  • 10g1 Linux x86 silent install  orapwd remote_login_passwordfile  ORA-01031

    I have completed a silent install of 10g1 EE on Linux x86 followed by emca on command line, executed orapwd to create orapwdSID file in $ORACLE_home/dbs with password for sys, set remote_login_passwordfile =EXCLUSIVE, am able to sqlplus connect / as

  • Time and Classifieds services missing after installing LabVIEW 8.0

    Hi, After installing LabVIEW 8.0 I noticed the Lookout Time and Classifieds services are missing.  At first I thought it was just the Lookout lighthouse in the system tray which had disappeared but when checking in services.msc I can see that the ser

  • *.indd file extension issue - InDesignCC 2014 - Windows 7

    I cannot get any file with the *.indd file extension to associate with InDesignCC 2014 in windows 7. When I try to use the "Open With" option, InDesignCC 2014 will not show up in the programs list, even if I manually select it. Should I uninstall / r