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

Similar Messages

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

  • How to Implement Auto tabbing feature in a table region???

    Hi All,
    I am trying to implement auto tabbing feature in one of my OAF page using java script which is actually working for individual items but
    while implementing the same for a table bean its not working. is there any way to implement this feature in OAF without using java script?
    if not could anyone give some rough java script for this feature? please this is urgent..
    Thanks in advance
    Sree

    Sree,
    check this if it helps ;
    https://forums.oracle.com/thread/963732
    Not sure we can set Focus in : PFR ,  I hope it is possible in only PR.
    Regards
    Sridhar

  • Implementation of Tab Screen in portlets

    I want to display two tabs which relate to different information in a portlet.
    Ex: Tab A Tab B
    When user clicks on Tab A , it displays Animal Information
    When user clicks on Tab B , it displays Birds Information
    The user is able to see both the tabs on single page. The default information is of Tab A.
    This is strictly a Tab Screen Implementation in portal.
    Is this possible?
    It seems to be achieved through Themes Navigation. As tabs can be created by applying css styles . Dont know not sure!
    Any idea?
    Thanks in advance.

    Hi !
    ya these are not tabs but looks like tabs and works same as tabs.
    follow these steps.
    1: take a "contents" div on mouse over,and click change contents of
    this div. such as
    <div name="contents" width="300" height="300"> </div>
    <a href="javascript:your_method()"><img src="tab_image.jpg"></a>
    2: on mouse click in java script change contents of div
    document.getElementById(tab_name).innerHTML = "CONTENTS";
    3: change image source too in same script which shows selected tab
    document.getElementByID(tab_image_name).src = "selected_tab.png";

  • How to implement Line number in JTextArea

    Hi
    I have seen some JTextArea with Line numbers How to do it
    Thankx

    I'm playing around with trying to make a Line Number component that will work with JTextArea, JTextPane, JTable etc. I'm not there yet, but this version works pretty good with JTextArea. At least it will give you some ideas.
    Good luck.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    public class LineNumber extends JComponent
         private final static Color DEFAULT_BACKGROUND = new Color(230, 163, 4);
         private final static Color DEFAULT_FOREGROUND = Color.black;
         private final static Font DEFAULT_FONT = new Font("monospaced", Font.PLAIN, 12);
         // LineNumber height (abends when I use MAX_VALUE)
         private final static int HEIGHT = Integer.MAX_VALUE - 1000000;
         // Set right/left margin
         private final static int MARGIN = 5;
         // Line height of this LineNumber component
         private int lineHeight;
         // Line height of this LineNumber component
         private int fontLineHeight;
         private int currentRowWidth;
         // Metrics of this LineNumber component
         private FontMetrics fontMetrics;
         *     Convenience constructor for Text Components
         public LineNumber(JComponent component)
              if (component == null)
                   setBackground( DEFAULT_BACKGROUND );
                   setForeground( DEFAULT_FOREGROUND );
                   setFont( DEFAULT_FONT );
              else
                   setBackground( DEFAULT_BACKGROUND );
                   setForeground( component.getForeground() );
                   setFont( component.getFont() );
              setPreferredSize( 9999 );
         public void setPreferredSize(int row)
              int width = fontMetrics.stringWidth( String.valueOf(row) );
              if (currentRowWidth < width)
                   currentRowWidth = width;
                   setPreferredSize( new Dimension(2 * MARGIN + width, HEIGHT) );
         public void setFont(Font font)
              super.setFont(font);
              fontMetrics = getFontMetrics( getFont() );
              fontLineHeight = fontMetrics.getHeight();
         * The line height defaults to the line height of the font for this
         * component. The line height can be overridden by setting it to a
         * positive non-zero value.
         public int getLineHeight()
              if (lineHeight == 0)
                   return fontLineHeight;
              else
                   return lineHeight;
         public void setLineHeight(int lineHeight)
              if (lineHeight > 0)
                   this.lineHeight = lineHeight;
         public int getStartOffset()
              return 4;
         public void paintComponent(Graphics g)
              int lineHeight = getLineHeight();
              int startOffset = getStartOffset();
              Rectangle drawHere = g.getClipBounds();
    //          System.out.println( drawHere );
    // Paint the background
    g.setColor( getBackground() );
    g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
              // Determine the number of lines to draw in the foreground.
    g.setColor( getForeground() );
              int startLineNumber = (drawHere.y / lineHeight) + 1;
              int endLineNumber = startLineNumber + (drawHere.height / lineHeight);
              int start = (drawHere.y / lineHeight) * lineHeight + lineHeight - startOffset;
    //          System.out.println( startLineNumber + " : " + endLineNumber + " : " + start );
              for (int i = startLineNumber; i <= endLineNumber; i++)
                   String lineNumber = String.valueOf(i);
                   int width = fontMetrics.stringWidth( lineNumber );
                   g.drawString(lineNumber, MARGIN + currentRowWidth - width, start);
                   start += lineHeight;
              setPreferredSize( endLineNumber );
         public static void main(String[] args)
              JFrame frame = new JFrame("LineNumberDemo");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              JPanel panel = new JPanel();
              frame.setContentPane( panel );
              panel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
              panel.setLayout(new BorderLayout());
              JTextArea textPane = new JTextArea();
              JScrollPane scrollPane = new JScrollPane(textPane);
              panel.add(scrollPane);
              scrollPane.setPreferredSize(new Dimension(300, 250));
              LineNumber lineNumber = new LineNumber( textPane );
              lineNumber.setPreferredSize(99999);
              scrollPane.setRowHeaderView( lineNumber );
              frame.pack();
              frame.setVisible(true);

  • Tab to change component focus not "real tab" in jtextarea

    Hi,
    Assume you have four text field in one panel. The first text field get focus. Then you press tab, the focus will change to next text field... and so on..... If you put one text area in that panel..... the story begins....
    When you press tab in text area, it will do "real tab" in that text area....
    How do I disable that? I want it so that when you press tab in text area, it will change the focus to next element not do "real tab"...
    Thank you.

    Feel free to remove parts of the code that you feel
    are not required. The code was only posted as a
    suggestion. If there are some lines of code that you
    don't want then please remove then. You are under no
    obligation to use the code as posted. To make the
    code shorter you could try shortening the method
    names. I used "tabForward" and "tabBackward". You
    could use "f" and 'b" to shorten the names.Hehe, nice to have you back.

  • Implementation Of Tabbed panel in JSF

    I have 4 different tabs and i have only one jsp when i click that tab i have to go to particular part. using tabbed panel in JSF
    Please suggest me how can i approach.
    Thanks in advance
    Satish Cheedalla

    there are many different componentas for tab panel.
    The myfaces project offer this component in tomahawk project and tobago project.
    The are of course many commercial tab panel in various ajax frameworks.

  • How can I implement multiple windows/tabs in my Main-Menu?

    I don't really know how to explain it. As an example, Skype has roughly 20 windows bundled with it, that are switched to when you click things like "Skype-Home" and "Profile". The layout changes too drastically to change the way it looks through just code, and it's not a new window being opened, it stays in the same window, the same main-window. I was wondering if this is possible through Cocoa-Applescript, and if so, what are the necessary steps to achieve this.
    Taking it one step further, and if the above is possible, how could I implement a "tab" system in the application? The image below is an example of what I mean.

    AppleScriptObjC can use pretty much everything in the Cocoa API, so yes, it is possible.
    Note that a view is not the same as a window, and a window can have multiple views. There are also many ways to implement "tabs";  take a look at some of Apple's applications - they use various mixtures of toolbars, checkboxes, and radio buttons, for example.  An application such as this will be a lot more involved than what you have done so far though, using custom classes and subclassing existing ones, so be prepared to do a lot of reading and researching.

  • Soft proofing - implementation suggestions

    Reading this thread it seems the Lightroom team is seriously considering or actually implementing soft proofing for LR3.0. Since it's not in the current beta, the users cannot give feedback on the implementation. Instead, let's use this thread to give suggestions on how soft proofing should work.
    Here are my suggestions:
    availability: soft proofing should be available in all modules: you need it for print and web output, but the necessary corrections are made in the develop and library modules.
    UI placement: the film strip seems to be a logical place for a tool that can be used from within all modules.
    features: soft proofing would need an on/off toggle, a clipping indicator toggle and a list menu to select/create soft proofing profiles (with a choice of relative/perceptual; black point would be nice but doesn't fit the 'lightroom way').
    monitor proofing: make it easy for users to select the profile corresponding to their monitor. That way they get a warning that their monitor may be 'cheating' them (especially on laptops).
    further: the tool could show a warning if it is switched on with the 'wrong' profile for the active module. For example, for web you should only use sRGB, for print the same as selected for the printer and for the slideshow perhaps only the monitor profile.
    Anyone else?
    Simon

    Jeff Schewe wrote:
    I disagree for several reason: 1) the Develop module is the ONLY color accurate viewing environment, 2) Develop already has a before/after built in that can be adapted to the task of showing a before and an after with the after representing the output space. 3) the Develop module allows the creation and or selection of Develop templates as well as snapshots. Snapshots might make an excellent vehicle for carrying image adjustments.
    I am not sure what you mean by the develop module being the only color accurate viewing environment. I just checked it by setting my monitor gamma to 1.0, and all modules applied the necessary adjustments to the images. The only difference I could find is that the other modules use heavily compressed JPGs, leading to the occasional artifact when viewing at 1:1.
    I really believe that soft proofing itself is fundamentally an analysis tool that should be accessible from all modules, and not necessarily be linked to image adjustment tools. If someone wants to work on a set of images for a particular output process, he/she should be able to make all necessary changes with soft proofing turned on, and have the effects visible in all modules. Of course, in practice many users will want to target different output media for the same image, and such tools are important, but need not be a show-stopper for soft-proofing to appear.
    On your number (2), I personally don't find before/after view essential, or even that useful, when making adjustments for printing. When you want to compress an image into the gamut of a printer, I tend to make small adjustments in the context of that particular image, not with a reference to some master image. The exception to this case would be if you really have something which you would call the 'master' (say, some really famous image), and you want the output to be as close as possible on more restricted printing process. In any case, I wouldn't consider a before/after view as essential. And when it's needed, it could be implemented by an on/off toggle as well, IMO.
    I find snapshots quite cumbersome, and especially for the purpose of keeping track of such 'output versions'. The problem is that they exist inside the develop module, they are 'all or nothing', and there is no easy way to transfer partial settings between snapshots. For example, suppose I have three 'output versions' of an image, and I decide to change some of the underlying settings (say, the white balance). Then I don't have an easy way to synchronize these changes between the output versions. Another issue is that there is no easy way to recall snapshots from outside the develop module. If I want to print a couple of images for which I have the necessary adjustments at some other time, I have to go in and select the appropriate snapshot for each of them. In the context of these 'output versions', this is something that should be possible from the library module, where you select the versions you have worked on before.
    Also note that while Develop might be the place for adjusting the image for the output, the creation of an output adjustment might be best called up in Print (or Export). So you might create a saved preset that contains the output device, the specific profile, the rendering intent and whatever output based adjustments the image (or images) may need. That could be done directly in the Print module...
    The three main factors that soft proofed adjustments require is a change in the tone curve required by differences in dynamic range or outputs, hue and saturation adjustments to counter or alter the way a profile may render a certain (or several) colors and a local area contrast adjustment in the form of Clarity. Ideally, the soft proofing tools should contain a soft proofed histogram, color samples in the output space and tone/color adjustments suited for correcting for the output condition.
    Ok, I can see a benefit to a separate output adjustment tool that is specifically aimed for the type of adjustments you'd make when soft-proofing. The settings for this tool could be linked to the output device and profile, so that they would switch automatically according to the profile that is selected. When soft-proofing is turned on in the library module, there could be an icon in the images for which a particular output transformation is defined. And because soft-proofing would be fully functional in the develop module, you could inspect which other images need further adjustments.
    I don't think it's very useful to have a 'preset' for this tool for a particular output profile and rendering intent, independent of the image. That's the job of the profile itself. However, it should be possible to easily copy-paste such settings between images. For example, if I have shots a number of images in bright green grass, I will probably need similar adjustments for all of them. Also, settings should be copyable to serve as a starting point for use with a different profile.
    The 'output adjustment tool' itself should IMO contain two things:
    1) Photoshop-like hue/sat control (with selectable color ranges) [most important]
    2) Manual tone curve adjustments.
    I wouldn't mind if the tool is only accessible from within the develop module, as long as you can see the soft-proof from all modules. The soft-proofing functionality (separate from this tool) should also take care of adjusting the histogram in the library and develop modules.
    Summarinzing, I see room for two separate tool sets that do not necessarily need to be implemented at the same time. The first is an overarching soft-proofing solution that makes the effects of the output transformation visible throughout the workflow. The second is a separate output adjustment tool in the develop module, that is able to link it's settings to the currently selected output device/profile.
    Simon

  • 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

  • Override "crtl + tab" key behaviour with "tab" key for JtextArea .

    I am trying to override the "crtl + tab" key behaviour for JTextArea with "tab" key plus add my own action. I am doing the following.
    1. Setting Tab as forward traversal key for the JTextArea (the default traversal key from JTexArea is "crtl + Tab").
    2. Supplementing the "crtl + Tab" key behaviour with my custom behaviour.
    For the point 2 above, I need to get hold of the Action represented by the "crtl + Tab" key so that I could use that and then follow with my own custom action. But the problem is that there is no InputMap entry for "crtl + tab". I dont know how the "crtl + tab" key Action is mapped for JTextArea. I used the following code to search the InputMap.
                System.out.println("Searching Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i);
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                System.out.println("Searching Parent Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i).getParent();
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                }In short, I need to get the Action associated with the "crtl + tab" for JTextArea.
    regards,
    nirvan.

    There is no Action for Ctrl+TAB. Its a focus traversal key.

  • [SOLVED] Reverting Guake terminal tab names back to 'Terminal #'

    The new version of Guake (0.4.3) implemented 'Better Tab Titling'.  This means that instead of a new tab name being 'Terminal #' (where # is an auto incrementing integer), it instead forced the title to be equal to the VTE prompt.
    My issues were that there was no way to set a preference to switch back (as I prefer the simple tab name) and that tab names could/would take a very large amount of space (as it would put my whole username@server:/path/to/where/i/am/at).
    So   I figured out how to fix and thought I'd share in case anyone else would like to switch back:
    NOTE:  I believe python is spacing-sensitive (please correct me if I'm wrong).  All the lines (added/edited) are indented 8 spaces.
    edit /usr/bin/guake
    find: self.selected_tab = None
    after that line, add:
            # holds the number of created tabs. This counter will not be
            # reset to avoid problems of repeated tab names.
            self.tab_counter = 0
    find: def on_terminal_title_changed(self, vte, box):
    after that line add:
            return
    find: Adding a new radio button to the tabbar
    the next line will read:
            label = box.terminal.get_window_title() or _("Terminal")
    change to:
            label = box.terminal.get_window_title() or _('Terminal %s') % self.tab_counter
    find self.tabs.pack_start(bnt, expand=False, padding=1)
    after that line add:
            self.tab_counter += 1
    After editing the file, restart Guake for the change to take effect.
    Beemer

    I have been using Guake for years and I think the tab bar is in the way. I disabled it a very long time ago and didn't look back.
    Here are the shortcuts that I use:
    "~" to toggle it.
    Ctrl+T for a new tab (just like in Firefox, Chromium).
    F1 and F2 for next and previous tab.
    F3 close tab.
    Basically, I don't need more than two tabs at a time; three tops, in very rare cases.
    Hope it helps.

  • Tabs and stacked canvases ...

    Why are tab canvases effectively implemented as stacked canvases? It seems crazy that you have to first create a "content" canvas (which will never have any items placed on it) on which to display your tab canvas!
    I want to create the layout where I have a stacked canvases (scrolling spread table) positioned on one of my tabs. As a stacked canvas is attached to a "window" there appears no way to tell forms that this stacked canvas applies to say the first tab! So when I go to the second tab, the stacked canvas is still visible!
    Do I have to write canvas manipulation code to manage this?? Am I going to get it to work??
    It all appears like the forms group has taken a quick (and dodgy) approach to "finally" implementing native tab functionality! (even the case tool won't generate this layout)
    I shouldn't have to write code to do this!

    Hi ,
    Did u ever get any answer from the Forms - group? I am having problems with stacked item groups displayed on a tab page. Mouse navigation on that same tab page or even shift-TAB results in dissapearance of the stacked item groups.
    Can U help?
    Greets Aschwin

  • Forms 5 Tab Canvas & Horizontal Scrollbar

    We are trying to implement a tab canvas which will hold a multi-record data block. The difficulty is that we would like to display a lot of fields and there is no Horizontal Scrollbar easily available for the Tab Canvas.
    We are thinking about "simulating" a tab canvas by using stacked canvases. The stacked canvas allows us to have the scrollbar, but looses some of the look & feel of a tab canvas.
    Anyone try to do this in Forms 5? How about anyone try to place a stacked canvas on top of a tab canvas?

    We're using forms 6.0.8.8. Our standard practice is to never put items on a tab canvas, instead we put stacked canvas' on the tab canvas. Besides having canvas scroll bars, it also provides a basis to work around documented bugs for refreshing/resizing windows when returning from other forms/windows of different sizes etc.
    null

  • Addtional tab CI field not getting updated in table

    Hi all,
    I am using cProjects 4.0 system.
    I had implemented addtional custom tab to display project custom include fields. In CI include of dpr_project table i added custom fields.
    Then created new webdynpro component and in implemented interface tab in had implemented DPR_CUST_EXT_INTF.  In view i displayed the 2 custom fields i added. In cProjects SPRO, i had given my component name for addtional tab. When I run the application it is showing those fields i added in addtional tab. While saving it is not updating custom field. Please let me know what needs to be done.
    Thanks & Regards,
    Karthick S

    Hi,
    For adding custom fields from CI_* includes, I advise you to use available feature in SAP standard 'field groups for customer fields' under : SPRO -> Collaboration Projects -> Global Enhancements to Project Elements.
    This is the easiest way to add custom tabs & fields without webdynpro development. All standard functions are supported: field control, save, BADI...
    BR
    Matthias

Maybe you are looking for

  • Hi how to add new folders under root for jsp in tomcat4.1.18

    hi, previsously i used tomcat3.3 and tomcat4.1.12 run sucessfully. now i downloed jakartha_tomcat4.1.18, i am running sample succesfuly direcly under root. now i want my some jsp appilcationes to run under xyz,pqr folders here my jsp files are abc.js

  • PDFs not updating in CS6

    Hello- We recently upgraded from CS4 to CS6. Several artists since then have informed me that their PDFs are not being updated if they make a change and then overwrite the existing PDF. Basically, we make changes to an ad in ID (it happened in Quark

  • Incorrect artist name for all songs by that artist

    Recently something weird has happened to my music library on my iPhone 5S (iOS 8.2 before, but I've updated to 8.3 and still the issue persists). All the songs by a particular artist have the artist name listed wrongly. For example, I have about 50 K

  • Unable to charge ipod shuffle

    I am unable to charge my ipod shuffle. It will not show in itunes or on my computer.

  • IPods Not Recognised by SL (Causing Problems)

    Initial installation of SL was fine, but then iTunes wouldn't recongise my iPod Mini and iPod Nano 1G (even after resetting both iPods). Without thinking, I then restarted my Mac with the iPod Mini still in its docking station. After initial reboot,