Setting focus to a JTextArea using tab

Hi,
I have a JPanel with a lot of controls on it. When I press tab I want to
move focus to the next focusable component. This works fine for
JTextFields, but when the next component is a JTextArea in a
JScrollPane then I have to press tab 3 times to set the focus to the
JTextArea. After pressing the tab key once I think the focus is set to
the scrollBars of the JTextArea because when I press the up and down
arrows the textarea is scrolled.
How can I stop the JScrollPane from getting the focus?
I have tried to set focusable to false on the scrollPane:
scrollPanel.setFocusable(false);
and the scrollBars of the scrollPane:
scrollPanel.getHorizontalScrollBar().setFocusable(false);
scrollPanel.getVerticalScrollBar().setFocusable(false);
But it dosen�t work. Is this a completely wrong way of doing it?
Please help!
I use jdk 1.4.1
:-)Lisa

Not sure what your problem is. The default behaviour is for focus to go directly to the JTextArea.
import java.awt.*;
import javax.swing.*;
public class Test1 extends JFrame
     public Test1()
          getContentPane().add( new JTextField("focus is here"), BorderLayout.NORTH );
          getContentPane().add( new JButton("Button1") );
          getContentPane().add( new JScrollPane( new JTextArea(5, 30) ), BorderLayout.SOUTH );
     public static void main(String[] args)
          Test1 frame = new Test1();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);
}

Similar Messages

  • Cannot set focus when reset data using datasets

    Hi All,
    When I click reset form button. I would like to reset data then focus to the first field. I can clear information I provided but setFocus to the first name field is not working. Please help.
    I use datasets to reset data. 
    Here is my coding:
    event: click
    xfa.datasets.data.loadXML("<form1/>", true, true);
      xfa.host.setFocus("xfa.form1.contactInformation.firstname")
    Thanks,
    Cindy

    I tested the clear button. But it is not set Focus to the first field. It is not successful.

  • Setting focus to component in new tab

    I have a static function in my main class with a JTabbedPane as a parameter...the function does this:
    //Add a tab
    tabs.addTab("New File", new STab());
    tabs.setSelectedIndex(tabs.getTabCount()-1);
              ((JPanel)tabs.getSelectedComponent()).getComponent(0).requestFocusInWindow();
    I run this function from two different places in my code: one is from a menu I created when a user mouse clicks on the menu item. The other is when the user presses Ctrl+T...this goes through a KeyEventDispatcher that I set up on top of all my other components.
    The problem is this: when I create a new tab through the menu, the code that selects the first component in my tab works, however when I do it with Ctrl+T that component is not selected. Both of these methods run the same function...the only difference is that the Ctrl+T method goes through a class which implements my own interface.
    Any ideas?

    tabs.setSelectedIndex(tabs.getTabCount()-1);
    this will select the last tab in your tabbed pane...
    I assume the next line is when the tabbed pane is hidden behind some other frame, it will bring it to front.
    ((JPanel)tabs.getSelectedComponent()).getComponent(0).requestFocusInWindow();
    couldn't you just go:
    tabs.getSelectedComponent().requestFocus(); ? I'm not 100% what you're tryin to do in the last line.

  • How to use tab key with JTextArea to shift focus

    Hi
    My problem is simple as whenevr i use tab key in my JTextArea, instaed of shifting focus to next component, it adds a tab space to my text.
    How do i shift focus out of my JTextArea.
    Ashish

    you can also redefine the textarea's TAB Key behaviour. The tutorial has a good example for that - better than i would be able to describe :-)
    look at http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html

  • How to set current row in table after use tab key on inputText

    Hello all,
    My first post .., I'm newbie in ADF and I will try to explain my problem.
    For the moment we use ADF 11g (11.1.1.4), in a jsff page I have a table with an inputText column.
    On the valueChangeListener of the inputText, I invoke a method in a viewScope bean which call an EJB method, make some services in the EJB on the line modified. After that I refresh the VO and the table (because others values on the line have been modified) and reset the focus on the same inputText modified by the user with javaScript because focus was lost after refresh.
    So far, everything works fine.
    When I use the arrow keys to change the selected row in the table, it's work fine (focus is still in the next or previous inputText), but if user try to use tab key to change the current line, the inputText on the next line have the focus but the current row of the table is not changed (I think it's normal).
    My question : how can I change the current row after tab key pressed in this case ?
    I don't know if it's really clear, not easy to explain, don't hesitate to ask more details.
    Thanks in advance.

    Frank Nimphius wrote:
    Hi,
    My question : how can I change the current row after tab key pressed in this case ?
    Use a client event to listen for the keyboard entry and intercept the tab. The use af:serverListener to call the server to set the rowKey on the table and issue a PPR for the table to re-paint
    See sample 11 on http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html#CodeCornerSamples
    to learn about how to use the client listener and server listener
    FrankHi,
    Thanks a lot for your advices, I used the client and server listener
    I used this code on the method call in order to change the selection after key tab pressed, I don't know if it can be easier, but it works.
              if (LOGGER.isDebugEnabled()) {
              LOGGER.debug("START changeSelectedRow");
              RowKeySet oldRowKeySet = myTable.getSelectedRowKeys(); // get oldRowKeySet
              if (oldRowKeySet == null) {
                   if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("oldRowKeySet is null");
                   return;
              RowKeySetImpl newRowKeySet = new RowKeySetImpl(); // The new RowKeySet use to change the selectedRow
              DCIteratorBinding bindingIterator = ADFUtils.findIterator(MY_ITERATOR);
              bindingIterator.setRangeSize(-1);
              // set the new index of the current row.
              int index = bindingIterator.getCurrentRowIndexInRange();
              if (index < bindingIterator.getAllRowsInRange().length - 1) {
                   index++;
              bindingIterator.setCurrentRowIndexInRange(index);
              // get the current row after changed the index
              Row currentRow = bindingIterator.getCurrentRow();
              if (currentRow != null) {
                   ArrayList nextLst = new ArrayList(1);
                   nextLst.add(currentRow.getKey());
                   newRowKeySet.add(nextLst);
                   // set the new selectedRow
                   myTable.setSelectedRowKeys(newRowKeySet);
                   SelectionEvent selectionEvent = new SelectionEvent(oldRowKeySet, newRowKeySet, myTable);
                   selectionEvent.queue();
                   AdfFacesContext.getCurrentInstance().addPartialTarget(myTable);
              if (LOGGER.isDebugEnabled()) {
                   LOGGER.debug("END changeSelectedRow");
    Best Regards
    Benjamin

  • Tab not changing focus in a JTextArea

    Hi
    I am writing a little program that at a certain point uses a JTextArea. What bugs me a lot is that the JTextArea keeps focus when I press the Tab button
    I see two solutions to this.
    Either I extend JTextArea into MyJTextArea and override the processKeyEvent method and from there address the processKeyEvent method from JTextComponent class
    so the processKeyEvent method from JTextArea never gets a chance at catching the tab.
    The second solution would be to once again extend the JTextArea class and override the processKeyEvent method, and in the method check whether tab was pressed, and in that case change the focus myself
    I don't know if the first is possible, but the second should work. I'm actually rather curious about the first one. So if anyone can help me out in either addressing the super-superclass of MyJTextArea or in changing the focus manually without creating too much of a fuss, I'd be very, very thankfull
    Thx in advance!
    Pieter

    the previous post it's rigth, you can leave the JTextArea using ctrl+tab, but if you really need pass the focus out of the JTextArea with only press tab you can do something like this     myTextArea.setDocument(new PlainDocument() {
              public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
                  if (str.equalsIgnoreCase("\t"))
                        FocusManager.getCurrentManager().focusNextComponent(myTextArea);
                   else
                        super.insertString(offs, str, a);
         }); hope this helps
    lalo s.

  • Setting focus to a jsf component inside a tab.

    Hi,
    How can I set focus to a jsf component that is placed on some tab other then the first. Suppose that on the 2nd tabitem of the tab. there are some components on this tab . How can I set the focus to any one of these components on tabitem2 when the jsf page is opened.
    Any ideas..
    Thanks in advance..

    Use Javascript.var el = document.getElementById('elementId');
    if (el && el.focus) {
        el.focus();
    }

  • DATAGRID FOCUS ISSUE: Focus got lost, while moving from one cell to another cell using tab key.

    Problem: Focus got lost, while moving from one cell to another cell using tab key.
    Example: In an AdvanceDataGrid, there are three columns having custom ItemRenderer with Spark TextInput control (editable=true & focusEnabled=true).
    When I try to move the focus in with in 2nd, 3rd & 4th column using tab key, focus got lost. Most of the time it’s working, but some time it doesn’t work. There’s no clue as to how may rows/columns the focus has jumped to; or whether the focus has gone out of the data grid altogether.
    Observations: I am not sure whether this problem is because of custom component implementation or it is because of some issue related to Flex Component.
    It only occurs when we perform some actions like some server call, some complex logic execution etc. at the focus out event of itemrenderer.
    There is one property of datagrid i.e. editedItemPosition which contains row & column index of datagrid. On the focus out event, it gets null when focus got lost. We tried to set it, but it didn’t work.
    Steps Performed:-
    1. Currently focus is in 2nd column i.e. Apply to #.
    2. Once I press tab key from 2nd column, it goes to 3rd column which is correct.
    3. Now if I press tab key from 2nd column i.e. Payment #, focus should go to 3rd column, but it goes out of data grid and set the focus of button which is outside data grid.

    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2Bjtable+%2Btab+%2B%22enter+key%22&col=javaforums

  • Problem using Setting Focus

    Hello there, can you help me on how to use the set Focus.
    For instance I have a 3 JTextField, when I run it, the focus is on the first textField, what I want is that, when I pressed the enter key on the keyBoard, the focus will be on the 2nd textField, and when I pressed again the enter key, the focus will be on the 3rd textField and so on.
    can you give me a sample code on this one, thanks.

    the last post in this thread might give you some ideas
    http://forum.java.sun.com/thread.jspa?threadID=713697&tstart=0
    note: will only work if the textfields follow each other in the focus traversal policy

  • How to set focus on a textinput/poplist using PPR

    HI,
    Is it possible to use PPR to set focus on a Text input or Poplist.
    if Yes, which attribute in the UI Item we need to use?
    will the attribute 'Access Key' work for the same?
    If PPR is not an option then getting a java bean for the UI Item is the only option?
    Thanks,
    Gowtam.

    Gowtam,
    No, the two basic differences between PPR and fire action!
    1)Fire action submit the entire OA Page Form elements, while PPR only refreshes the form components of that particular region.
    2)When PPR event is done, framework neglects any other action done on the page.
    Now, like your basic question, why should u use PPR event ?Instead y not firaction always?
    The reason is the very first defination of PPR.If i have n number of items on my page, if I define every action as fire action after each event page will refresh, so even for a small update like vanishing a field, i have to refresh the entire page which will be unusual for the user because it will take some time to load if page has some heavy components like hgrids , tables etc. Thats y we prefer PPR event over fire action in case of individual events, which is much fast, refreshing only particular form items.
    In standard j2ee web applications, the same is done using DHTML and javascript.
    I hope i am clear.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • HT1178 I have set up Time Capsule to use with Time Machine.  When I open Time Machine it 'cannot find' the Time Capsule and I have the Select the Disk each time.  In the Next Backup tab it always says "When disk is connected" even though the disk is alrea

    I have set up Time Capsule to use with Time Machine but when I open Time Machine it 'cannot find' the Time Capsule and I have to 'Select the Disk' each time. In the Next Backup tab it always says "When disk is connected" even though the disk is already connected.

    Your pro doesn't matter.. I presume it is happily working.
    Your imac setup has got messed up because you changed from a local (my book being USB type I presume) to network drive. Did you do a clean install of Lion?
    Did you use the backup from the Pro on the imac? Otherwise I don't see how the Pro shows up in use previous disk. Where is Pondini when you need him??
    You cannot download Time Machine as an App and replace the current version. It is built into the OS.. the only way to do it is a clean install. Unfortunately that might be the only way around the issue.
    There is a number of issues that Pondini has covered in the setup issues of troubleshooting.
    This is the most relevant I think. http://pondini.org/TM/B6.html
    But look at the whole section B setup problems.
    http://pondini.org/TM/Troubleshooting.html
    If it was me, I would store all the info you need.. not using TM but using a straight copy of files.
    Then clean install Lion. I doubt any of these issues would exist if you had not installed Lion over existing setup or used a different backup.
    See if you can get Pondini to respond.. !!

  • How to set focus on a custom PO Item screen field when in error?

    Hi All,
    I have an interesting situation that i'm wondering if others have solved.  We have extended the PO item table (EKPO) by adding two new fields.  We then have implemented two BAdI's:  ME_GUI_PO_CUST and ME_PROCESS_PO_CUST to add them to the ME21N/ME22N/ME23N screens and logic to do some validation, via these respective BAdI's mentioned.  Everything works perfectly - with one small issue.  When we are doing some validation via a method on the ME_PROCESS_PO_CUST - and "invalidate" the field (and throw an error) when it is in error - I also want to be able to "set focus" on the field in question (basically: go to the particular tab on the ME* screen and highlight the field).  I have tried using SET CURSOR FIELD *****  within this BAdI (ME_PROCESS_PO_CUST) - but doesn't seem to work.  Has anyone tried to do this and have come up with a solution?  Would be much appreciative if you shared it!!!  Thanks much.
    Cheers,
    Matt
    ERP version that we have is:  ECC 6.0

    Just have a look at oss note 310154 - ME21N/ME51N: Customer-specific check, generating error log.
    In short:
    Add your error messages in EXIT_SAPMM06E_012 (using specific macros).
    Sample code (provided in Oss note) :
      loop at tekpo where knttp eq 'X'.
        loop at tekkn where ebeln eq tekpo-ebeln and
                            ebelp eq tekpo-ebelp and
                            kostl eq space.
          if not tekkn-id is initial.
            mmpur_business_obj_id tekkn-id.
            mmpur_metafield MMMFD_ACCOUNTINGS.
          endif.
          mmpur_message_forced 'E' 'ZE' '777' '' '' '' ''.
        endloop.
      endloop.

  • Setting focus in a PDF form

    Hi,
    I'm trying to move a cursor to a particular field based on certain conditions using JavaScript. The method I am using is xfa.host.setFocus("fldTest"); in the initialize event. For some reason the focus isn't getting set to fldTest, but when I first hit tab it goes into the first field that is in the tab order. Is there any way around this?
    Thanks,
    Chad

    You might want to check the reference path of the field that you want to set focus on.
    Ex: xfa.host.setFocus("form1.page1.subform1.TextField1");

  • JOptionPane.showConfirmDialog  "NO" button acting as "YES" on MAC using TAB

    JOptionPane.showConfirmDialog "NO" button acting as "YES" on MAC using TAB

    Ya , I am asking question ? Why "NO" is acting as "YES" button in case of JOptionPane.showConfirmDialog on MAC using TAB.
    i.e,
    I clicked on some button, then showConfirmDialog is opened, By default the focus is on "YES" button. Now I pressed TAB button and changed to the focus to "NO" button.
    If press ENTER key --> acting "YES"
    If press SPACE key -> acting as "NO"
    Why ?
    What should I do to make it correct ?
    Am I need mention set (Key,value) pairs for UIManager in case of MAC.
    Please suggest ?

  • Setting focus to new instance of a field...need help.

    Hi there,
    I have a flowed form which consists of multiple subforms. I have one subform which is basically one textfield that is set to a min of 1 and a max of 5.
    These are to correspond to fields in our system of record that have 5 fields for company long name with a 36 character field limit.
    I've got the limits set up just fine and I have added simple script to add a new instance when the user exits the field.
    The focus goes to the next field set in the tab order but what I want is the focus set on the new instance of field created but I have not been able to find an example of how to do that.
    Any suggestions would be greatly appreciated. Thanks!

    Well,
    I've been reading and trying various things but cant get anything to work like I want it to.
    The sample provided works for 2 iterations but mine has to do this for up to 5 instances. I have not been able to figure out how to get this to work.
    Anyone have any additional suggestions?
    btw...here is my modified version. ES2 is whay I'm using.
    Long_Title.occur.max = "5";
    var oSubform = xfa.resolveNode("Long_Title");
    var oNewInstance = oSubform.instanceManager.addInstance(1); // I think you probably managed this first part better than here
    xfa.form.recalculate(1); // I THINK THIS IS IMPORTANT
    var count = (this.Long_Title.nodes.length)
    var testIndex = oNewInstance.Account_Long_Title.index;
    xfa.host.messageBox("Text Field Index in new Subform: " + count); // TextField1 will conserve index 0 because it is the only textfield in the new Sub1
    var NEW_TEXTFIELD = xfa.resolveNode("Long_Title[1].Account_Long_Title[0]"); // However, Sub1 gets index 1 because it is not alone any more
    xfa.host.setFocus(NEW_TEXTFIELD); // This actually sets focus on the newly created instance of TextField1 (actually Sub1 instance)

Maybe you are looking for