JTextArea tab??

Hi everyon in the forum,
i am adding some text to a JText Area and i was wondering if it is possible to make sometrhing like tabulation, so the text will appear in form of two columns in the right positions.
For the moment i just added the lines, but it does not work
textArea.append("\n      "+ labels[i] + "     "+ values[i] + "   \n");Thanks

Hi everyon in the forum,
i am adding some text to a JText Area and i was
wondering if it is possible to make sometrhing like
tabulation, so the text will appear in form of two
columns in the right positions.
For the moment i just added the lines, but it does
not work
textArea.append("\n      "+ labels[i] + "     "+
values[i] + "   \n");ThanksUse the TAB character: '\t'
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class TabTest {
    TabTest() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextArea ta = new JTextArea();
        ta.setTabSize(10);
        ta.append("Left Column 1" + "\t" + " Right Column 1" + "\n");
        ta.append("Left Column 2" + "\t" + " Right Column 2" + "\n");
        ta.append("Left Column 3" + "\t" + " Right Column 3" + "\n");
        ta.append("Left Column 4" + "\t" + " Right Column 4" + "\n");
        ta.append("Left Column 5" + "\t" + " Right Column 5" + "\n");
        ta.append("Left Column 6" + "\t" + " Right Column 6" + "\n");
        ta.append("Left Column 7" + "\t" + " Right Column 7" + "\n");
        ta.append("Left Column 8" + "\t" + " Right Column 8" + "\n");
        ta.append("Left Column 9" + "\t" + " Right Column 9" + "\n");
        ta.append("Left Column 10" + "\t" + " Right Column 10" + "\n");
        f.add(ta);
        f.setSize(400,300);
        f.setVisible(true);
    public static void main(String[] args) {
        new TabTest();
}

Similar Messages

  • JTextArea - Tab problem

    When I'm in the text area when I press Tab key it's inserted into the text area but I want it to go to the next focusable component. Could you help? How do I do it?

    I incorporated a more generic solution of Michaels suggestion with some other examples I have found:
        This is my understanding of how tabbing works. The focus manager
        recognizes the following default KeyStrokes for tabbing:
        forwards:  TAB or Ctrl-TAB
        backwards: Shift-TAB or Ctrl-Shift-TAB
        In the case of JTextArea, TAB and Shift-TAB have been removed from
        the defaults which means the KeyStroke is passed to the text area.
        The TAB KeyStroke inserts a tab into the Document. Shift-TAB seems
        to be ignored.
        This example shows different approaches for tabbing out of a JTextArea
        Also, a text area is typically added to a scroll pane. So when
        tabbing forward the vertical scroll bar would get focus by default.
        Each approach shows how to prevent the scrollbar from getting focus.
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextAreaTab extends JFrame
        public TextAreaTab()
            Container contentPane = getContentPane();
            contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
            contentPane.add( nullTraversalKeys() );
            contentPane.add( writeYourOwnAction() );
            contentPane.add( useKeyListener() );
            contentPane.add( addTraversalKeys() );
        //  Reset the text area to use the default tab keys.
        //  This is probably the best solution.
        private JComponent nullTraversalKeys()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Null Traversal Keys\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
            textArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
            return scrollPane;
        //  Replace the Tab Actions. A little more complicated but this is the
        //  only solution that will place focus on the component, not the
        //  vertical scroll bar, when tabbing backwards (unless of course you
        //  have manually prevented the scroll bar from getting focus).
        private JComponent writeYourOwnAction()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Write Your Own Tab Actions\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            InputMap im = textArea.getInputMap();
            KeyStroke tab = KeyStroke.getKeyStroke("TAB");
            textArea.getActionMap().put(im.get(tab), new TabAction(true));
            KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
            im.put(shiftTab, shiftTab);
            textArea.getActionMap().put(im.get(shiftTab), new TabAction(false));
            return scrollPane;
        //  Use a KeyListener
        private JComponent useKeyListener()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Use Key Listener\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            textArea.addKeyListener(new KeyAdapter()
                public void keyPressed(KeyEvent e)
                    if (e.getKeyCode() == KeyEvent.VK_TAB)
                        e.consume();
                        KeyboardFocusManager.
                            getCurrentKeyboardFocusManager().focusNextComponent();
                    if (e.getKeyCode() == KeyEvent.VK_TAB
                    &&  e.isShiftDown())
                        e.consume();
                        KeyboardFocusManager.
                            getCurrentKeyboardFocusManager().focusPreviousComponent();
            return scrollPane;
        //  Add Tab and Shift-Tab KeyStrokes back as focus traversal keys.
        //  Seems more complicated then just using null, but at least
        //  it shows how to add a KeyStroke as a focus traversal key.
        private JComponent addTraversalKeys()
            JTextArea textArea = new JTextArea(3, 30);
            textArea.setText("Add Traversal Keys\n2\n3\n4\n5\n6\n7\n8\n9");
            JScrollPane scrollPane = new JScrollPane( textArea );
            scrollPane.getVerticalScrollBar().setFocusable(false);
            Set set = new HashSet( textArea.getFocusTraversalKeys(
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS ) );
            set.add( KeyStroke.getKeyStroke( "TAB" ) );
            textArea.setFocusTraversalKeys(
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set );
            set = new HashSet( textArea.getFocusTraversalKeys(
                KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS ) );
            set.add( KeyStroke.getKeyStroke( "shift TAB" ) );
            textArea.setFocusTraversalKeys(
                KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set );
            return scrollPane;
        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);
    }

  • Problematic focus traversal (JTextArea)

    I have a data entry dialog with several JTextFields and one JTextArea.
    Focus traversal (with the tab key) works nicely between instances of JTextField, but it is not possible to tab out of the JTextArea to the next JTextField (as a tab is inserted in the text area instead). I've have looked up swing focus traversal in books, but no cigar when it comes to dealing with JTextAreas
    Does anyone know how to fix this? I don't need to enter tabs into the text area.
    thanks,
    Andy

    There is a Swing forum for Swing related questions.
    Have you tried searching the forum?. Using keywords "+jtextarea +tab" would be a good place to start. You'll be amazed how many times this question has been asked/answered before.
         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()
              // Reset the FocusManager
              JTextArea textArea1 = new JTextArea(5, 30);
              textArea1.setText("1\n2\n3\n4\n5\n6\n7\n8\n9");
              JScrollPane scrollPane1 = new JScrollPane( textArea1 );
              getContentPane().add(scrollPane1, BorderLayout.NORTH);
              textArea1.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
              textArea1.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
              scrollPane1.getVerticalScrollBar().setFocusable(false);
              scrollPane1.getHorizontalScrollBar().setFocusable(false);
              //  Replace the Tab Actions
              JTextArea textArea2 = new JTextArea(5, 30);
              textArea2.setText("1\n2\n3\n4\n5\n6\n7\n8\n9");
              getContentPane().add(new JScrollPane(textArea2), BorderLayout.SOUTH);
              InputMap im = textArea2.getInputMap();
              KeyStroke tab = KeyStroke.getKeyStroke("TAB");
              textArea2.getActionMap().put(im.get(tab), new TabAction(true));
              KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
              im.put(shiftTab, shiftTab);
              textArea2.getActionMap().put(im.get(shiftTab), new TabAction(false));
         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);

  • 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();
    }

  • Tab in JTextArea

    hi,
    how can i deactivate the Tab in JTextArea.
    when i click on Tab in JTextArea i get a real Tab with 8 Chars(i can control the size!)
    but i want that Tab goes to the next Object.
    thx.

    And if you need to set the action yourself, you would use something like this (though you would want it a lot cleaner I would imagine...)
    KeyMap km = jTextArea.getKeyMap();
    km.removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));
    km.removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,KeyEvent.CTRL_MASK));
    Action tabAction = new Action(jTextArea) {
         private Component currentFocusOwner;
         public Action (Component comp) {
              currentFocusOwner = comp;
         public void actionPerformed(ActionEvent e) {
              currentFocusOwner.transferFocus();
    tabAction.putValue(Action.Action_Command_Key, "Tab");
    km.setActionForKeyStroke (KeyStroke.getKeyStoke(KeyEvent.VK_TAB,0), tabAction);You will want to look into the API for KeyMaps, Actions, and KeyEvents to put it all together (looking into the JTextArea heirarchy won't hurt either...)

  • Tabbing out of a JTextArea

    Hi
    Having a application with a number of textfields and a textarea, I would like to tab through (using the tab-key of course). The problem occurs in the textarea where the tab-key simply tabs along inside the textarea rather than moving on to the next textfield. How to fix that?
    By the way... the "nextFocusableComponent" function seems to be deprecated in "J2SE 1.4.0_01", I understand that the new way to do that kind of navigation in applications is by using the "FocusTraversalPolicy". How does that work?
    Regards
    /swaq

    I figured it out my self... Hope this will help others...
    import java.awt.*;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class AreaTest extends JFrame {
    private JTextArea area;
    private JTextField field;
    private Container contentPane;
    public AreaTest() {
    setSize(300,300);
    contentPane = getContentPane();
    area = new JTextArea();
    area.setLineWrap(true);
    area.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "none");
    area.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent event) {
    if( event.getKeyCode() == KeyEvent.VK_TAB )
    area.transferFocus();
    contentPane.add(new JScrollPane(area), BorderLayout.CENTER);
    field = new JTextField();
    contentPane.add(field, BorderLayout.SOUTH);
    class Test {
    public static void main(String[] args) {
    AreaTest area = new AreaTest();
    area.show();
    }

  • How do you tab out of JTextArea?

    When using the tab key to change focus from one
    JComponet to the next, how do you tab out of, and
    into next JComponent when you're in an editable
    JTextArea? Is it possible?

    Move to the bottom of the text in a JTextArea with VK_CONTROL + VK_END.
    Better yet, here is how to find all the input actions that you can trigger when focus is on a JTextArea (or any given JComponent)
    JTextArea text = new JTextArea();
    InputMap im = text.getInputMap();
    KeyStroke[] ks = im.allKeys();
    SortedMap map = new TreeMap();
    for(int i=0; i<ks.length; ++i)
        map.put(im.get(ks), ks[i]);
    for(Iterator i = map.entrySet().iterator(); i.hasNext() ; ) {
    Map.Entry pair = (Map.Entry) i.next();
    System.out.println(pair.getKey() + "\n\t" + pair.getValue());

  • Making the Tab key not work in the JTextArea

    In my view I have a JTextArea along with a bunch of JTextFields and JComboBoxes. The user is usually going to tab out of a field in order to go to the next field. What's happening is when the user tries to tab out of the JTextArea, the cursor just moves by a tab length within the JTextArea instead of going to the next field. And if the JextArea has some text in it and if the user tabs into the JTextArea, the whole text gets selected and on hitting the next tab, it gets wiped out.
    I am trying to make the JTextArea not respond to the tab by writing the following code. Keymap keyMap = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
    KeyStroke tabKey = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, false);
    keyMap.removeKeyStrokeBinding(tabKey);
    jTextArea1.setKeymap(keyMap);But it's still not working. Can anybody tell what's wrong with that code. Or is there any other way to do it? Any help/hints appreciated.
    Thanks.

    >
    If you're using jdk1.4, those other solutions won't
    work because the focus subsystem has changed radically
    (see
    http://java.sun.com/j2se/1.4/docs/api/java/awt/doc-file
    /FocusSpec.html). The upshot is that you have to
    specifically register the keystrokes that you want to
    use for focus traversal. In your case, you have to
    re-register the Tab and Shift-Tab keys, and
    they don't seem to have provided a simple way to do
    that. Here's what I come up with:Set forwardTraversalKeys = new TreeSet();
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(
    KeyEvent.VK_TAB));
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(
    KeyEvent.VK_TAB, InputEvent.CTRL_MASK));
    textArea.setFocusTraversalKeys(
    KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
    forwardTraversalKeys);
    Set backwardTraversalKeys = new TreeSet();
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(
    KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(
    KeyEvent.VK_TAB, InputEvent.SHIFT_MASK |
    K | InputEvent.CTRL_MASK));
    textArea.setFocusTraversalKeys(
    KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
    backwardTraversalKeys);Or, you can just press CTRL+TAB instead of TAB when
    you get to the JTextArea :).=====================================
    i used the above thing but i am getting exceptions classcast exception n method not found (forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB));)keystroke.get keyStroke(int)???? where i am going wrong as it will be quite helpful for me am using jdk1.4.1_02
    thnaks

  • Moving the Focus with the TAB key in a JTextArea Component

    Dear Friends,
    I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
    Thanx in advance.

    I had the same problem before. Here is what i did.
    JTextArea txtArea = new JTextArea(2,15);
    Set forwardTraversalKeys = new HashSet();     
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));          
    txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);          
    Set backwardTraversalKeys = new HashSet();          
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));          
    txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
    JScrollPane scrollPane = new JScrollPane(
         txtArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // the scrollbar of the JScrollPane is focusable that's why it requires
    // another TAB key to transfer the focus.
    scrollPane.getVerticalScrollBar().setFocusable(false);

  • Using TAB to focus next component in a JTextArea

    hello everybody,
    I would like to use the TAB-key in a JTextArea to focus the next component in my frame.
    I tried to use an KeyListener which calls an instance of javax.swing.FocusManager with the method
    focusNextComponent(Component c).
    My problem is, that - allthough I call consume() for the KeyEvent - the TAB is displayed im my JTextArea........
    how can I solve this, that the TAB is NOT visible?
    (plaese excuse my bad english )
    Thanks Chris

    The way to do it is use setNextFocusableComponent(Component c)
    so as you create each component, you can set the order that the tab key will give focus.
    eg
    JButton b1 = new JButton();
    JButton b2 = new JButton();
    b1.setNextFocusableComponent(b2);
    etc...
    The tab won't be displayed in the JTextArea then,.
    James

  • 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.

  • Retaining tab functionality in JTextArea

    Hi,
    How to ensure that from inside a text area, tab key leads to the next focussable component?
    In my application, when tab pressed inside a text area, focus doesnt go to the next component. Tab is printed in the text area instead. I do not want this.
    TIA,
    CA

    override the isManagingFocus method:
    JTextAreea textArea = new JTextArea( "one two", 3, 15 )
         public boolean isManagingFocus()
              return false;
    };

  • Switching tab behavior in JTextArea

    I think by default Multiline text areas in windows will tab to the next focusable component by pressing the tab button and will create a tab character within the text area by pressing ctrl-tab. JTextArea has the opposite behavior. Does anyone know how to make JTextArea have the default windows behavior? I've looked all over this site for two days and have tried many of the suggestions and many of my own ideas without being able to get this work. Please help if you can.
    porcaree

    i do have a similar problem.
    can u suggest me u r ideas.
    thanks
    vijay

  • Tab format/size in JTextArea not working

    Howdy, I am writing a program that uses Runtime.exec() method, I get the error stream from the new process, etc... all that works fine, but as I use append(String s) where s = StreamOutput+"\n";, the output is not formatted in the JTextArea. However, if I do System.out.println(s), the output is perfectly lined up.
    I recall reading somewhere about setting the tab size or something or other about a similar problem, but now cannot find the answer in the forums or the docs. Any assistance would be greatly appreciated.
    Brian

    here is the chunk of code in question:
    String[] commandLine = {profile.getCompilerPath(),filePath};
                   Process p = rt.exec(commandLine);
                   BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                   String s = reader.readLine();
                  while(s!=null)
                        writer.write(s2.toString());
                        System.out.println(s);
                        s = reader.readLine();
                   writer.write(null);writer is an instance of an innner calss of the gui, and its only method is write(String s). write does this: txtAreaOutput.append("\n" + s); if s !=null. having messed with tab sizes etc to no avail, I am at a loss. the output I am trying to capture is from the javac.exe compiler, imagine that! and the little carats that point to the errors don't line up with the code in the JTextArea. what's worst, notice the call to System.out.println(s) after the call to writer. this was to check to see that the output was coming out right, and there it is PERFECT!!! ahhhh. Please help if you can.
    Is there an issue that the JTextArea is not using a monospaced font, and if so, how do I fix that, or is there some other component with similar funcitonality that will work? Thank you for your time and mental sweat.. I am at my wit's end here :(

  • Implement soft tab in JTextArea?

    Hi
    Does anyone know how I can implement soft tab in
    JTextArea?
    Or put it this way, override default tabbing behaviour
    and inserts string " " whenever user press tab.
    Thanks in advance
    Okidoki

    For backspace you can do the same thing, removing only the previous character(s).
    class MyTabKey extends KeyAdapter {
         public void keyPressed(KeyEvent e) {
              int keyCode = e.getKeyCode();
              if (keyCode == KeyEvent.VK_TAB ) {
                   e.consume();
                   JTextArea textArea = (JTextArea)e.getSource();
                   int tabSize = textArea.getTabSize();
                   StringBuffer buffer = new StringBuffer();
                   for ( int i = 0; i < tabSize; i++ )
                   buffer.append(" ");
                   textArea.insert( buffer.toString(), textArea.getCaretPosition() );
              if (keyCode == KeyEvent.VK_BACK_SPACE) {
                   e.consume();
                   JTextArea textArea = (JTextArea)e.getSource();
                   int tabSize = textArea.getTabSize();
                   int end  = textArea.getCaretPosition()-1;
                   int start  = end - tabSize;
                   textArea.replaceRange("",  start, end);
    }Hope this helps,
    Denis

Maybe you are looking for

  • Why is it so hard to copy pictures from my iPhone to my iPad?

    I want to use iCloud to backup both my iPhone and iPad, but not any of the pictures on these devices.  I want to backup the pictures to my iMac, since they take up so much space.  What is the best way to do this?  What is the correct way to copy pict

  • Inconsistent Previewing Raw Files in Bridge

    About two weeks ago, without warning, I was no longer able view my raw files in bridge. The strange thing is, when looking at raw files from a CD in bridge, it will give a preview of about 75% of the files. I am running leopard on my MAC OS X 10.5.4,

  • Changing an asset from non depreciating to depreciating

    Good afternoon, We have an asset which, when created, was non-operational and was created with depreciation key 000. We now need to change the depreciation to the key ZDEP (which is straight line depreciation) from 01.04.2009. Get error message "E662

  • IOS 8.3 and blank App/iTunes Store

    Since I updated to iOS 8.3  I can't connect to Apps store or Exchange server.  I tried logging out of my app store and itunes  thinking it just needed to reconnect and now I can't get back in.  Also some apps are not working at all.  Anyone else havi

  • Month end provision entries

    hi all, how to generate Month end provision entries. pls give one example . regards, supriya thodimela.