Tab traversal in TextArea

I have the following code so that when the TAB key is pressed, focus traverses to the next field. All is well EXCEPT...before it traverses to the next field, it inserts a TAB character into the control, indenting any existing content.
I don't want that.
Help
        srcListing.setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                if (event.getCode() == KeyCode.TAB) {
                    srcDescription.requestFocus();
                    event.consume();
        });

Hi James. Your code looks ok, but the explanation is not correct:
In this example, both event filters and event handlers work.
Event filters are called during the event capturing phase of event handling.
   srcListing.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
            public void handle(KeyEvent event) {
                if (event.getCode() == KeyCode.TAB) {
                    srcDescription.requestFocus();
                    event.consume();
        });Event handlers are called during the event bubbling phase.
  srcListing.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
            public void handle(KeyEvent event) {
                if (event.getCode() == KeyCode.TAB) {
                    srcDescription.requestFocus();
                    event.consume();
        });

Similar Messages

  • How can we prevent JTabbedPanes from transferring focus to components outside of the tabs during tab traversal?

    Hi,
    I noticed a strange focus traversal behavior of JTabbedPane.
    During tab traversal (when the user's intention is just to switch between tabs), the focus is transferred to a component outside of the tabs (if there is a component after/below the JTabbedPane component), if using Java 6. For example, if using the SSCCE below...
    import java.awt.BorderLayout;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TabbedPaneTest extends JPanel {
        public TabbedPaneTest() {
            super(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            add(new JScrollPane(panel));
        private JPanel buildPanelWithChildComponents() {
            JPanel panel = new JPanel();
            BoxLayout boxlayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
            panel.setLayout(boxlayout);
            panel.add(Box.createVerticalStrut(3));
            for (int i = 0; i < 4; i++) {
                panel.add(new JTextField(10));
                panel.add(Box.createVerticalStrut(3));
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneTest());
                    frame.pack();
                    frame.setVisible(true);
    ... Then we can replicate this behavior by following these steps:
    1) Run the program in Java 6; and then
    2) Click on a child component in any of the tabs; and then
    3) Click on any other tab (or use the mnemonic keys 'ALT + 1' to 'ALT + 4').
    At step 3 (upon selecting any other tab), the focus would go to the component below the JTabbedPane first (hence the printed message in the console), before actually going to the selected tab.
    This does not occur in Java 7, so I'm assuming it is a bug that is fixed. And I know that Oracle suggests that we should use Java 7 nowadays.
    The problem is: We need to stick to Java 6 for a certain application. So I'm looking for a way to fix this issue for all our JTabbedPane components while using Java 6.
    So, is there a way to prevent JTabbedPanes from passing the focus to components outside of the tabs during tab traversal (e.g. when users are just switching between tabs), in Java 6?
    Note: I've read the release notes between Java 6u45 to Java 7u15, but I was unable to find any changes related to the JTabbedPane component. So any pointers on this would be deeply appreciated.
    Regards,
    James

    Hi Kleopatra,
    Thanks for the reply.
    Please allow me to clarify first: Actually the problem is not that the child components (inside tabs) get focused before the selected tab. The problem is: the component outside of the tabs gets focused before the selected tab. For example, the JButton in the SSCCE posted above gets focused when users switch between tabs, despite the fact that the JButton is not a child component of the JTabbedPane.
    It is important for me to prevent this behavior because it causes a usability issue for forms with 'auto-scrolling' features.
    What I mean by 'auto-scrolling' here is: a feature where the form automatically scrolls down to show the current focused component (if the component is not already visible). This is a usability improvement for long forms with scroll bars (which saves the users' effort of manually scrolling down just to see the focused component).
    To see this feature in action, please run the SSCCE below, and keep pressing the 'Tab' key (the scroll pane will follow the focused component automatically):
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JViewport;
    import javax.swing.SwingUtilities;
    public class TabbedPaneAutoScrollTest extends JPanel {
        private AutoScrollFocusHandler autoScrollFocusHandler;
        public TabbedPaneAutoScrollTest() {
            super(new BorderLayout());
            autoScrollFocusHandler = new AutoScrollFocusHandler();
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            button.addFocusListener(autoScrollFocusHandler);
            JScrollPane scrollPane = new JScrollPane(panel);
            add(scrollPane);
            autoScrollFocusHandler.setScrollPane(scrollPane);
        private JPanel buildPanelWithChildComponents(int numberOfChildComponents) {
            final JPanel panel = new JPanel(new GridBagLayout());
            final String labelPrefix = "Dummy Field ";
            final Insets labelInsets = new Insets(5, 5, 5, 5);
            final Insets textFieldInsets = new Insets(5, 0, 5, 0);
            final GridBagConstraints gridBagConstraints = new GridBagConstraints();
            JTextField textField;
            for (int i = 0; i < numberOfChildComponents; i++) {
                gridBagConstraints.insets = labelInsets;
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = i;
                panel.add(new JLabel(labelPrefix + (i + 1)), gridBagConstraints);
                gridBagConstraints.insets = textFieldInsets;
                gridBagConstraints.gridx = 2;
                textField = new JTextField(22);
                panel.add(textField, gridBagConstraints);
                textField.addFocusListener(autoScrollFocusHandler);
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6 with auto-scrolling");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneAutoScrollTest());
                    frame.setSize(400, 300);
                    frame.setVisible(true);
    * Crude but simple example for auto-scrolling to focused components.
    * Note: We don't actually use FocusListeners for this feature,
    *       but this is short enough to demonstrate how it behaves.
    class AutoScrollFocusHandler extends FocusAdapter {
        private JViewport viewport;
        private JComponent view;
        public void setScrollPane(JScrollPane scrollPane) {
            viewport = scrollPane.getViewport();
            view = (JComponent) viewport.getView();
        @Override
        public void focusGained(FocusEvent event) {
            Component component = (Component) event.getSource();
            view.scrollRectToVisible(SwingUtilities.convertRectangle(component.getParent(),
                    component.getBounds(), view));
    Now, while the focus is still within the tab contents, try to switch to any other tab (e.g. by clicking on the tab headers, or by using the mnemonic keys 'ALT + 1' to 'ALT + 4')...
    ... then you'll notice the following usability issue:
    1) JRE 1.6 causes the focus to transfer to the JButton (which is outside of the tabs entirely) first; then
    2) In response to the JButton gaining focus, the 'auto-scrolling' feature scrolls down to the bottom of the form, to show the JButton. At this point, the tab headers are hidden from view since there are many child components; then
    3) JRE 1.6 transfers the focus to the tab contents; then
    4) The 'auto-scrolling' feature scrolls up to the selected tab's contents, but the tab header itself is still hidden from view (as a side effect of the behavior above); then
    5) Users are forced to manually scroll up to see the tab headers whenever they are just switching between tabs.
    In short, the tab headers will be hidden when users switch tabs, due to the Java 6 behavior posted above.
    That is why it is important for me to prevent the behavior in my first post above (so that it won't cause usability issues when we apply the 'auto-scrolling' feature to our forms).
    Best Regards,
    James

  • Tab Traversal problem in JTable

    Hi all,
    I am having a requirement in my current project to traverse across the cells of a JTable. Some of the cells were set CustomCelleditor(mainly textfield).
    I have gone through the threads in this forum and tried a code snippet which is now highlighting the text on tab traversal. But there are 2 problems with which I am facing with :-
    1. I need to press tab twice to move to the next cell(one is stopping cell editing and the other is to traverse to the next cell).
    2. When I moved from cell 1 to cell2 using tab and then click on cell1, the text is not getting highlighted.
    Please help me in resolving these issues ?
    The code I tried includes :-
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import javax.swing.text.*;
    public class TableSelectAll extends JFrame{
         JTable table;
         public TableSelectAll() {     
              Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"}, {"4", "D"} };
              String[] columnNames = {"Number","Letter"};
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              table = new JTable(model) {   
              public void changeSelection(int row, int column, boolean toggle,
    boolean extend) {
              super.changeSelection(row, column, toggle, extend);
                   SwingUtilities.invokeLater( new Runnable(){                 
                   public void run() {    
                        table.dispatchEvent(new KeyEvent( table,                               KeyEvent.KEY_PRESSED,
                             0,
                             0,
                             KeyEvent.VK_F2,
                             KeyEvent.CHAR_UNDEFINED) );
                   JScrollPane scrollPane = new JScrollPane( table );
                   getContentPane().add( scrollPane );
                   MyCellEditor dce = new MyCellEditor( new SelectAllEditor() );
                   dce.setClickCountToStart( 1 );
                   table.setDefaultEditor(Object.class, dce );
         class SelectAllEditor extends JTextField implements FocusListener { 
              public SelectAllEditor() {           
              setBorder( new LineBorder(Color.black) );
              addFocusListener( this );
    public void setText(String text) {
         super.setText(text);
         System.out.println("text");
         selectAll();
    public void focusGained(FocusEvent e) { 
         System.out.println("gained");
         if (getSelectionStart() == getSelectionEnd())
         selectAll();
         public void focusLost(FocusEvent e) {}
    class MyCellEditor extends DefaultCellEditor {
    public MyCellEditor(JTextField t) {
    super(t);
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int
    row, int column) {
    final Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column);
    if (c != null && c instanceof JTextField) {
    try {
    c.requestFocus();
    } catch (Exception e) {
    //handleException(e);
    return c;
    public static void main(String[] args) {   
         TableSelectAll frame = new TableSelectAll();
         frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.pack(); frame.setVisible(true);
    Regards
    Nagalakshmi

    Additional info:[http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=017300]

  • Tab traversal sequence in panelFormLayout

    Hi,
    How to change tab traversal sequence in panelFormLayout to Left to Right and Top to Bottom Z pattern.
    Currently it is following Top to bottom and then left to right
    using Jdev Version 11.1.1.5.0
    Thanks

    Put multiple PanelFormLayout instead of one and inside one panelform layout put all the component in one column only. See the example below :
    PanelGroupLayout - horizontal
    -- PanelFormLayout
    -- inputText
    -- inputText
    -- PanelFormLayout
    -- inputText
    -- inputText
    Code Snippet -
    <af:panelGroupLayout id="pgl1" layout="horizontal">
    <af:panelFormLayout id="pfl1">
    <f:facet name="footer"/>
    <af:inputText label="Label 1" id="it1"/>
    <af:inputText label="Label 1" id="inputText1"/>
    <af:inputText label="Label 1" id="inputText2"/>
    </af:panelFormLayout>
    <af:panelFormLayout id="panelFormLayout1">
    <f:facet name="footer"/>
    <af:inputText label="Label 1" id="inputText3"/>
    <af:inputText label="Label 1" id="inputText4"/>
    <af:inputText label="Label 1" id="inputText5"/>
    </af:panelFormLayout>
    <af:outputText value="outputText1" id="outputText3"/>
    </af:panelGroupLayout>

  • Getting Focus using TAB key in TextArea

    Hi,
    When I move the focus into a TextArea with a TAB. The first pressed key is not displayed. Is this a bug..? if yes are there any workarounds..? I am using JDK1.4.1.
    I am pasting my sample program.
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends Frame implements KeyListener {
         public static void main (String args[]) {
              Test t = new Test();
         public Test() {
              TextField tf = new TextField(10);
              TextArea ta = new TextArea (10,5);
              tf.addKeyListener(this);
              ta.addKeyListener(this);
              this.add(BorderLayout.NORTH,tf);
              this.add(BorderLayout.SOUTH,ta);
              this.setSize(500,500);
              this.setVisible(true);
    public void keyPressed(KeyEvent kE) {
         System.out.println("KEY PRESSED");
    public void keyReleased(KeyEvent kE) {
         System.out.println("KEY RELEASED");
    public void keyTyped(KeyEvent kE) {
         System.out.println("KEY TYPED");
    Thanks,

    Quick bit of cut and paste here from an app that I've just modified + thrfr this is tested;- class EventKeyHandler implements KeyListener, ClipboardOwner{
         public void keyTyped(KeyEvent e){}
         public void keyPressed(KeyEvent e){                                        
            switch (e.getKeyCode()) {
               case 9: keyMethods(e.getSource(), e.getKeyCode());
                   break;
               // etc
         public void keyMethods(Object myObject, int i){
              JTextPane component = (JTextPane) myObject;
              if(!hasBeenDone[qCount]){
              StringBuffer temp = new StringBuffer(component.getText() );
                   if(i==9){
                        temp = temp.append("tab");
                        component.setText(temp.toString() );
                   }

  • Regarding Radio Button Tab Traversal

    Hi All,
    Iam Using the JGoodies , I have the RadioButtons in
    my application . Here my problem is when I traverse through the Tab , focus is moving to the Deselected RadioButton label , which should not happen . Is there any way to avoid this ?
    Can any body have the idea in this scenerio ...pls help me.
    Thanks in Advance

    Well, yes of course this happens. You need to move to deselected buttons to give the user a chance to "select" the button.
    Not everybody uses a mouse and you application should not be designed to force a user to use the mouse.

  • JTextPane - Need to override TAB insert for traversal

    I am using the JTextPane for HTML support. I want the TAB key to default to traversing components instead of inserting tabs or spaces. For JTable and JTextArea I was able to clear the focus traversal keys and they correctly defaulted to the standard component method (i.e., Tab traverses components)
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    This works for JTextPane when using plain content ("text/plain") but not HTML content ("text/html"). I assume it is because of the default editor that is installed in each case, but i can not figure out how to change the behavior or the editor (e.g., HTMLEditorKit).
    Any help would be geatly appreciated.

    I did a quick test using method 1 on a JTextPane without HTML and it seemed to work. I'll let you test it when it's using the HTMLEditorKit:
         This example shows two different approaches for tabbing out of a JTextArea
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextAreaTab extends JFrame
         public TextAreaTab()
              //  Replace the Tab Actions (this is the solution I prefer)
              JTextArea textArea1 = new JTextArea(5, 30);
              textArea1.setText("1\n1\n3\n4\n5\n6\n7\n8\n9");
              JScrollPane scrollPane1 = new JScrollPane( textArea1 );
              getContentPane().add(scrollPane1, BorderLayout.NORTH);
              InputMap im = textArea1.getInputMap();
              KeyStroke tab = KeyStroke.getKeyStroke("TAB");
              textArea1.getActionMap().put(im.get(tab), new TabAction(true));
              KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
              im.put(shiftTab, shiftTab);
              textArea1.getActionMap().put(im.get(shiftTab), new TabAction(false));
              // Reset the FocusManager
              JTextArea textArea2 = new JTextArea(5, 30);
              textArea2.setText("2\n2\n3\n4\n5\n6\n7\n8\n9");
              JScrollPane scrollPane2 = new JScrollPane( textArea2 );
              getContentPane().add(scrollPane2, BorderLayout.SOUTH);
              textArea2.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
              textArea2.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
              // (we don't want the scroll bar to receive focus)
              scrollPane2.getVerticalScrollBar().setFocusable(false); // for tabbing forwards
              scrollPane1.getVerticalScrollBar().setFocusable(false); // for tabbing backwards
         class TabAction extends AbstractAction
              private boolean forward;
              public TabAction(boolean forward)
                   this.forward = forward;
              public void actionPerformed(ActionEvent e)
                   if (forward)
                        tabForward();
                   else
                        tabBackward();
              private void tabForward()
                   final KeyboardFocusManager manager =
                        KeyboardFocusManager.getCurrentKeyboardFocusManager();
                   manager.focusNextComponent();
                   SwingUtilities.invokeLater(new Runnable()
                        public void run()
                             if (manager.getFocusOwner() instanceof JScrollBar)
                                  manager.focusNextComponent();
              private void tabBackward()
                   final KeyboardFocusManager manager =
                        KeyboardFocusManager.getCurrentKeyboardFocusManager();
                   manager.focusPreviousComponent();
                   SwingUtilities.invokeLater(new Runnable()
                        public void run()
                             if (manager.getFocusOwner() instanceof JScrollBar)
                                  manager.focusPreviousComponent();
         public static void main(String[] args)
              TextAreaTab frame = new TextAreaTab();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
    }

  • Tab Key Navigate from TextArea

    I know I must be missing something obvious here but...
    Hit the tab key in a TextField, and the focus passes to the next control. Hit the Tab key in a TextArea and it adds a tab (or four characters?) to the text.
    How do I make it so hitting the Tab key in TextArea navigates to the next control?

    Hi. You can do it like this:
    final TextField tf2 = new TextField();
            TextArea ta = new TextArea();
            ta.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                @Override
                public void handle(KeyEvent t) {
                    if (t.getCode() == KeyCode.TAB) {
                        tf2.requestFocus();
                        t.consume();
            });

  • TextArea Insertion at current Caret Position

    I am trying to figure out the best way to insert "text" in to
    a textarea at the current caret position. Anyone have tips for
    figuring out where to find this? In Flash you used to have
    CaretIndex,
    Im in the process of writing a code editor component, so
    first off Im capturing the TAB key event, and then will insert an
    actual TAB in the textarea... Right now I was just doing
    this.Editor.text = this.Editor.text + ' '; But this is a stupid
    stupid idea - so instead of appending it at the end, I need to
    insert it in the current caret position.
    Any tips would be greatly appreciated. Once I get it done, I
    will be releasing it under either the Apache or GPL license.

    Update: I have found
    var text:String = this.Editor.text;
    this.Editor.text =
    text.substr(0,this.Editor.selectionEndIndex) + " " +
    text.substr(this.Editor.selectionEndIndex);
    this.Editor.setSelection(this.Editor.selectionBeginIndex+1,this.Editor.selectionBeginIndex +1);

  • Please reconfirm previous SDN claim:  can't preset cursor movement by TAB!

    In this thread here:
    Tab Order Control on Custom Screens
    several SDNers offered the opinion that you can't set order of cursor movement by TAB key thru a screen.  (I am familiar with the SET CURSOR/GET CURSOR trick for controlling cursor movement by ENTER key.)
    Is it really true that you can't preset cursor movement by TAB key ???
    I could do this back in the 1980's and 90's with CICS and Model 204 User Language - seems strange that you can't do the same in ABAP, which is such a rich and robust language.
    Thanks
    djh

    Rich -
    Thank you for making an excellent point, which as usual, hadn't occurred to me.
    Of course, old-timers like me would say that what SAP should do is:
    1) add a TAB-traversal index number to the little box of properties you get in screen painter;
    2) pass the index numbers to SAPGui when the screen is first used;
    3) keep them in buffer and follow them each time the screen is entered.
    But what do us old-timers know? We grew up when there was just a mainframe talking to tubes with only some 3274's in the middle, and those only later ...
    Regards
    djh

  • First letter ignored in TextArea

    import java.awt.*;
    public class MyTextArea extends java.applet.Applet {
         TextField f1 = new TextField(20);
         TextField f2 = new TextField(20);
         TextArea ta = new TextArea(5, 50);
         public void init() {
              add(f1);
              add(f2);
              add(ta);
    When I tab into the TextArea diaplayed by running the above Applet, the first letter typed by me is ignored. But this does not happens when i click in the textarea and then type a letter!
    Also, the BackTab key doesn&#8217;t work in the TextArea. Why not?
    Can someone help?
    Many thanks

    guptamala,
    by default, the textarea keystroke is as follows:
    forward ctrl + TAB
    backward ctrl + shift + TAB
    so when you enter only TAB, I think it is a bug to allow to go into text area then ignore the first letter
    solution:
    a. if you follow default keystroke then you will be fine
    b. if you want to change the keystroke to TAB
    you can set new keystroke
    Set keystrokes = new TreeSet();
    keystrokes.add(AWTKeyStroke.getAWTKeyStroke("TAB"));
    ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keystrokes);
    here is the working solution
    import java.awt.*;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.util.Set;
    import java.util.TreeSet;
    public class MyTextArea extends java.applet.Applet {
         TextField f1 = new TextField(20);
         TextField f2 = new TextField(20);
         TextArea ta = new TextArea(5, 30);
         public void init() {
              add(f1);
              add(f2);
              add(ta);
              Set keystrokes = new TreeSet();
              keystrokes.add(AWTKeyStroke.getAWTKeyStroke("TAB"));
              ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keystrokes);
              requestFocus();
    Good luck

  • KeyTyped events not generated

    I've got a JTextArea. I wanted to allow focus traversal with standard TAB keys, so I provided a KeyListener that consumes TAB events. The problem is, that if I shift-tab to my textArea (it's placed in a JPanel), the first pressed key is ignored.
    After a little investigation it turns out, that for the very first key pressed after the JTextArea has gained focus no keyTyped event is generated - only keyPressed and keyReleased. Why is that? Why does it happen only after shift-tabbing to the JTextArea (tabbing to it does not produce this strange behaviour)?
         textArea.addKeyListener(new KeyAdapter() {
                   @Override
                   public void keyPressed(KeyEvent e) {
                                  if (e.getKeyCode() == KeyEvent.VK_TAB && (e.getModifiers() == 0 || e.getModifiers() == KeyEvent.SHIFT_MASK)) {
                             if (e.getModifiers() == KeyEvent.SHIFT_MASK) {
                                  textArea.transferFocusBackward();
                             } else {
                                  textArea.transferFocus();
                             e.consume();
                   }

    You might have better luck getting a helpful response if you create a Short, Self Contained, Correct (Compilable), Example or SSCCE. This is a small application that you create that is compilable and runnable, and demonstrates your error, but contains no extraneous, unnecessary code that is not associated with your problem. To see more about this and how to create this, please look at this link:
    http://homepage1.nifty.com/algafield/sscce.html
    Remember, this code must be compilable and runnable.
    I tried to create one of my own but could not reproduce your problem:
    import java.awt.GridLayout;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    class SwingFoo1 extends JPanel
        JTextArea[] textAreas = new JTextArea[3];
        SwingFoo1()
            setLayout(new GridLayout(0, 1));
            for (int i = 0; i < textAreas.length; i++)
                JPanel panel = new JPanel();
                JTextArea textArea = new JTextArea(5, 60);
                JScrollPane scrollpane = new JScrollPane(textArea);
                panel.add(scrollpane);
                add(panel);
                textAreas[i] = textArea;
                final int iFinal = i;
                textArea.addKeyListener(new KeyAdapter()
                    @Override
                    public void keyPressed(KeyEvent e)
                        if (e.getKeyCode() == KeyEvent.VK_TAB
                            && (e.getModifiers() == 0 || e.getModifiers() == KeyEvent.SHIFT_MASK))
                            if (e.getModifiers() == KeyEvent.SHIFT_MASK)
                                textAreas[iFinal].transferFocusBackward();
                            else
                                textAreas[iFinal].transferFocus();
                            e.consume();
            JPanel buttonPanel = new JPanel();
            JButton fooButton = new JButton("Foo");
            buttonPanel.add(fooButton);
            add(buttonPanel);
        private static void createAndShowGUI()
            JFrame frame = new JFrame("SwingFoo1 Application");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new SwingFoo1());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • How to create a custom focus manager in jdk1.4

    Dear All,
    I'm now trying to create a form for user to submit data. The key tab are easily to tab between textfields in html, you can set whatever order you want. But when I tried to create a form using java, I found very hard to do so. Any reference link and examples are appreciate.
    Thanks in advance
    Kitty

    cat8888,
    In general, tab-order is usaually the order you've added to the Panel / JPanel. When Panel is added to Panel and that to Panel and so on, sometimes the order can become less clear. When "trapped" inside a TextArea / JTextArea, the tab key takes on it's own meaning and now it wants to tab inside the TextArea. For this, you'll need special coding. For example, you might try adding code like this:
    myTextAreaObject.addKeyListener( new KeyAdapter() {
    public void keyPressed(KeyEvent ke) {
    if ( ke.getKeyCode() == ke.VK_TAB ) {
    myNextButtonObject.requestFocus();
    ... which effectively forces focus on - in this case - the JButton following the JTextArea.
    Not sure if this is what you mean, but HTH. And by the way, if someone has a neater way t odo this, I'd also like to know.
    ~Bill

  • Replace range still not working!

    I cannot get replaceRange to work properly on a textArea, with words longer or shorter than the word i want to replace it meeses it all up! here is my code:
    EditReplaceMenuItem.addActionListener(new ActionListener() {//action listener for "replace" menu item in edit menu
    public void actionPerformed(ActionEvent e) {
    String replace = JOptionPane.showInputDialog(null, "Replace:");//find word to replace
    String with = JOptionPane.showInputDialog(null, "With:");//get word to replace with
             int index = jtp.getSelectedIndex();//get selected tab index
             JTextArea textArea = textAreas.get(index);//get textarea coreesponding to tab
             String text = textArea.getText();//get text from that textarea
    //replace code
    int startIndex = 0;
    Scanner scan = new Scanner(text);
    while(scan.hasNext())
       String current = scan.next();
       if(current.equals(replace))
          int start = text.indexOf(replace, startIndex);
          int end = start + replace.length();
          textArea.replaceRange(with, start, end);
       startIndex += current.length();
    });     here is a series of scrennshots which may help you see my problem : )
    http://i41.photobucket.com/albums/e254/frahasio/howstrange.jpg
    please help!

    Is there a particular reason why you're not using
    replaceAll(String regex, String replacement)which is defined for Strings?
    #

  • Update record from a button

    Hi All,
    what I need is answered here Re: button and plsql code but still I can't make it work.
    I created a button with following properties.
    Name: COMPLETE
    Button Position: Region Template Position #CHANGE#
    Database Action: No Database Action
    I created a process called Mark_Complete
    Process Point: On Submit - After Computations and Validations
    Run Process: Once Per Page Visit (default)
    Under Source tab, in Process textarea, wrote below code:
    begin
    :P14_LAST_UPDATE_DATE := SYSDATE;
    :P14_LAST_UPDATED_BY := :APP_USER;
    :P14_ORDER_STATUS := 'COMPLETE';
    end;
    Under conditions tab , in When Button Pressed (Process after Submit When this Button is Pressed), I selected the COMPLETE button which is mentioned above.
    Yet when I open a record from a report and click on COMPLETE button, It does not set the Order_Status to 'COMPLETE'.
    Using APEX 3.2.1

    Hi,
    Just check you items (P14_LAST_UPDATE_DATE, P14_LAST_UPDATED_BY, P14_ORDER_STATUS) "Source Used".
    It should be "Only when current value in session state is null".
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

Maybe you are looking for

  • Slow folder item previews when opening files in Photoshop CS3

    Can anyone advise me on the best way to improve the speed of previewing folder items/contents when navigating to items through the photoshop CS3 file finder? For some reason, one of my studio Macs, running Mac OS 10.4.1, and PShop CS3 takes ages to b

  • IPhoto crashes on launch after upgrading to latest version on ios6

    After upgrading iPhoto to latest version available, it crashes after every launch, on my new iPad (the new iPad, iPad 3) What I have already tried: - delete all photos - leave just one album with one (not corrupted) photo - desync albums and resync w

  • Problem playing FSimulator 2003

    hello,i have a new msi geforce fx 5200(8907).playing flight simulator 2003 the cockpit is black.this issue is known to microsoft and upgrading the driver should solve the problem.i installed the latest nvidia driver version 4403,but the cockpit is st

  • Can EM12c Cloud Control agent be installed in a solaris zone?

    Can EM12c Cloud Control agent be installed in a solaris zone? If so, are Solaris 8 and Solaris 9 zones supported? thanks

  • Fonts jumbled on certain web pages

    On certain sites, the font overlaps certain elements of the page. http://i.imgur.com/IRI9JMk.png http://i.imgur.com/y1snpC8.png This happens in both chrome and firefox. Could this be a bug with the acceleration method used by xf86-video-intel? I reca