Remap tab to space

I'm simply trying to remap the tab key to input spaces, but aren't having much luck- any pointers would be appreciated:
public class MyTextPane
    extends JTextPane{
    public MyTextPane() {
      super();
      InputMap im = this.getInputMap();
      ActionMap am = this.getActionMap();
      //  Have the tab key work the same as the space key
      KeyStroke tab = KeyStroke.getKeyStroke("TAB");
      KeyStroke space = KeyStroke.getKeyStroke("SPACE");
      im.put(tab, im.get(space));
      am.put(im.get(space), am.get(space));
}I've also tried overriding the processKeyBinding method, but I get two spaces for every one I want:
public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {// TAB
      ks = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,  0);
      MyStyledDoc doc = (MyStyledDoc) this.getDocument();
     int pos = this.getCaretPosition();
      try{
         doc.insertString(pos, " ", null);
      }catch(BadLocationException ble){}
    return super.processKeyBinding(ks,e,condition,pressed);
  }

I'm simply trying to remap the tab key to input
spaces, but aren't having much luck- any pointers
would be appreciated:There is no entry in the ActionMap associated with the SPACE key, so your code does nothing but remove the action associated with TAB.
Here's some code that inserts a single SPACE when TAB is pressed:
KeyStroke tabStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0);
        Action spaceAction = new AbstractAction() {
            public void actionPerformed(ActionEvent ae) {
                try {
                    textPane.getDocument().insertString(textPane.getCaretPosition(), " ", null);
                } catch (BadLocationException ble) {
                    System.out.println("This error shoul be impossible");
                    ble.printStackTrace();
        textPane.getInputMap().put(tabStroke, spaceAction);

Similar Messages

  • Bug with Show Whitespace and tab and space characters in SQL comments

    If Preferences > Code Editor > Display > Show Whitespace Characters is checked, and I type the following in SQL Worksheet:
    --A[tab]B[space]C
    It renders with two spaces between B and C. The first one is a blank space without the light dot character used to signify a space character, and the second space is filled with the dot character. The caret is then blinking before the C instead of after it:
    --A[tab]B[space][dot][|]C
    Further selection actions and editing in the region produce "corrupted" results. I've tried changing fonts, but there was no change to the behavior. Multiple tabs before the B produce multiple blank spaces immediately after it, and when placed at the end of the line the caret is then shown another space to the left of the C:
    --A[tab][tab]B[space][space][|][dot]C
    If I turn off Show Whitespace Characters the rendering immediately corrects, and caret placement, selection action, and editing behaviors all work as expected.
    This is observed on OS X with both the Mac OS X and Oracle/Fusion Blue look and feels.
    Ian
    About
    Oracle SQL Developer 3.0.04
    Version 3.0.04
    Build MAIN-04.34
    Copyright © 2005, 2011 Oracle. All Rights Reserved.
    IDE Version: 11.1.1.4.37.59.31
    Product ID: oracle.sqldeveloper
    Product Version: 11.1.2.04.34
    Version
    Component     Version
    =========     =======
    Java(TM) Platform     1.6.0_24
    Oracle IDE     3.0.04.34
    Versioning Support     3.0.04.34
    Properties
    Name     Value
    ====     =====
    apple.awt.graphics.UseOpenGL     false
    apple.awt.graphics.UseQuartz     false
    apple.laf.useScreenMenuBar     true
    awt.nativeDoubleBuffering     true
    awt.toolkit     apple.awt.CToolkit
    class.load.environment     oracle.ide.boot.IdeClassLoadEnvironment
    class.load.log.level     CONFIG
    class.transfer     delegate
    com.apple.macos.smallTabs     true
    com.apple.mrj.application.apple.menu.about.name     SQL_Developer
    com.apple.mrj.application.growbox.intrudes     false
    file.encoding     MacRoman
    file.encoding.pkg     sun.io
    file.separator     /
    ftp.nonProxyHosts     local|*.local|169.254/16|*.169.254/16
    gopherProxySet     false
    ice.browser.forcegc     false
    ice.pilots.html4.ignoreNonGenericFonts     true
    ice.pilots.html4.tileOptThreshold     0
    ide.AssertTracingDisabled     true
    ide.bootstrap.start     1309201485440911000
    ide.build     MAIN-04.34
    ide.conf     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
    ide.config_pathname     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
    ide.debugbuild     false
    ide.devbuild     false
    ide.extension.search.path     sqldeveloper/extensions:jdev/extensions:ide/extensions
    ide.firstrun     true
    ide.java.minversion     1.6.0_04
    ide.main.class     oracle.ide.boot.IdeLauncher
    ide.patches.dir     ide/lib/patches
    ide.pref.dir     /Users/ibrandt/.sqldeveloper
    ide.product     oracle.sqldeveloper
    ide.splash.screen     splash.gif
    ide.startingcwd     "/Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin"
    ide.user.dir     /Users/ibrandt/.sqldeveloper
    ide.user.dir.var     IDE_USER_DIR
    ide.vcs.noapplications     true
    ide.work.dir     /Users/ibrandt/sqldeveloper
    ilog.propagatesPropertyEditors     false
    java.awt.graphicsenv     apple.awt.CGraphicsEnvironment
    java.awt.printerjob     apple.awt.CPrinterJob
    java.class.path     ../../ide/lib/ide-boot.jar
    java.class.version     50.0
    java.endorsed.dirs     /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed
    java.ext.dirs     /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext
    java.home     /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    java.io.tmpdir     /var/folders/rq/rqQtue9lEpGAwCKh2hL8MU+++TM/-Tmp-/
    java.library.path     .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
    java.naming.factory.initial     oracle.javatools.jndi.LocalInitialContextFactory
    java.protocol.handler.pkgs     oracle.jdevimpl.handler
    java.runtime.name     Java(TM) SE Runtime Environment
    java.runtime.version     1.6.0_24-b07-334-10M3326
    java.specification.name     Java Platform API Specification
    java.specification.vendor     Sun Microsystems Inc.
    java.specification.version     1.6
    java.util.logging.config.file     logging.conf
    java.vendor     Apple Inc.
    java.vendor.url     http://www.apple.com/
    java.vendor.url.bug     http://bugreport.apple.com/
    java.version     1.6.0_24
    java.vm.info     mixed mode
    java.vm.name     Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.name     Java Virtual Machine Specification
    java.vm.specification.vendor     Sun Microsystems Inc.
    java.vm.specification.version     1.0
    java.vm.vendor     Apple Inc.
    java.vm.version     19.1-b02-334
    jdbc.library     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/jdbc/lib/ojdbc6.jar
    line.separator     \n
    log.file.name     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/extensions/oracle.datamodeler/log/datamodeler.log
    mrj.build     10M3326
    mrj.version     1060.1.6.0_24-334
    oracle.home     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper
    oracle.ide.util.AddinPolicyUtils.OVERRIDE_FLAG     true
    oracle.jdbc.mapDateToTimestamp     false
    oracle.translated.locales     de,es,fr,it,ja,ko,pt_BR,zh_CN,zh_TW
    oracle.xdkjava.compatibility.version     9.0.4
    orai18n.library     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/jlib/orai18n.jar
    os.arch     x86_64
    os.name     Mac OS X
    os.version     10.6.8
    path.separator     :
    reserved_filenames     con,aux,prn,lpt1,lpt2,lpt3,lpt4,lpt5,lpt6,lpt7,lpt8,lpt9,com1,com2,com3,com4,com5,com6,com7,com8,com9,conin$,conout,conout$
    socksNonProxyHosts     local|*.local|169.254/16|*.169.254/16
    sqldev.debug     false
    sun.arch.data.model     64
    sun.awt.exception.handler     apple.awt.CToolkit$EventQueueExceptionHandler
    sun.boot.class.path     ../../rdbms/jlib/ojdi.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:
    /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar
    sun.boot.library.path     /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries
    sun.cpu.endian     little
    sun.cpu.isalist     
    sun.io.unicode.encoding     UnicodeLittle
    sun.java.launcher     SUN_STANDARD
    sun.java2d.ddoffscreen     false
    sun.jnu.encoding     MacRoman
    sun.management.compiler     HotSpot 64-Bit Server Compiler
    sun.os.patch.level     unknown
    svnkit.sax.useDefault     true
    user.country     US
    user.dir     /Applications/Development/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin
    user.home     /Users/ibrandt
    user.language     en
    user.name     ibrandt
    user.timezone     America/Los_Angeles
    windows.shell.font.languages     
    Extensions
    Name     Identifier     Version     Status
    ====     ==========     =======     ======
    Check For Updates     oracle.ide.webupdate     11.1.1.4.37.59.31     Loaded
    Code Editor     oracle.ide.ceditor     11.1.1.4.37.59.31     Loaded
    Component Palette     oracle.ide.palette1     11.1.1.4.37.59.31     Loaded
    Data Miner     oracle.dmt.dataminer     11.2.0.1.10.109     Loaded
    Database Connection Support     oracle.jdeveloper.db.connection     11.1.1.4.37.59.31     Loaded
    Database Object Explorers     oracle.ide.db.explorer     11.1.1.4.37.59.31     Loaded
    Database UI     oracle.ide.db     11.1.1.4.37.59.31     Loaded
    Diagram Framework     oracle.diagram     11.1.1.4.37.59.31     Loaded
    Diagram Javadoc Extension     oracle.diagram.javadoc     11.1.1.4.37.59.31     Loaded
    Diagram Thumbnail     oracle.diagram.thumbnail     11.1.1.4.37.59.31     Loaded
    Diff/Merge     oracle.ide.diffmerge     11.1.1.4.37.59.31     Loaded
    Extended IDE Platform     oracle.javacore     11.1.1.4.37.59.31     Loaded
    External Tools     oracle.ide.externaltools     11.1.1.4.37.59.31     Loaded
    File Support     oracle.ide.files     11.1.1.4.37.59.31     Loaded
    Help System     oracle.ide.help     11.1.1.4.37.59.31     Loaded
    History Support     oracle.jdeveloper.history     11.1.1.4.37.59.31     Loaded
    Import/Export Support     oracle.ide.importexport     11.1.1.4.37.59.31     Loaded
    Index Migrator support     oracle.ideimpl.indexing-migrator     11.1.1.4.37.59.31     Loaded
    JDeveloper Runner     oracle.jdeveloper.runner     11.1.1.4.37.59.31     Loaded
    JViews Registration Addin     oracle.diagram.registration     11.1.1.4.37.59.31     Loaded
    Log Window     oracle.ide.log     11.1.1.4.37.59.31     Loaded
    Mac OS X Adapter     oracle.ideimpl.apple     11.1.1.4.37.59.31     Loaded
    Navigator     oracle.ide.navigator     11.1.1.4.37.59.31     Loaded
    Object Gallery     oracle.ide.gallery     11.1.1.4.37.59.31     Loaded
    Oracle IDE     oracle.ide     11.1.1.4.37.59.31     Loaded
    Oracle SQL Developer     oracle.sqldeveloper     11.1.2.04.34     Loaded
    Oracle SQL Developer - 3rd Party Database Browsers     oracle.sqldeveloper.thirdparty.browsers     11.1.1.04.34     Loaded
    Oracle SQL Developer - DBA Navigator     oracle.sqldeveloper.dbanavigator     11.1.1.04.34     Loaded
    Oracle SQL Developer - Extras     oracle.sqldeveloper.extras     1.1.1.04.34     Loaded
    Oracle SQL Developer - File Navigator     oracle.sqldeveloper.filenavigator     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Antlr3 Translator     oracle.sqldeveloper.migration.translation.core_antlr3     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Application Migration     oracle.sqldeveloper.migration.application     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Core     oracle.sqldeveloper.migration     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations DB2     oracle.sqldeveloper.migration.db2     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations DB2 Translator     oracle.sqldeveloper.migration.translation.db2     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Microsoft Access     oracle.sqldeveloper.migration.msaccess     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Microsoft SQL Server     oracle.sqldeveloper.migration.sqlserver     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations MySQL     oracle.sqldeveloper.migration.mysql     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Sybase Adaptive Server     oracle.sqldeveloper.migration.sybase     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations T-SQL Translator     oracle.sqldeveloper.migration.translation.core     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Teradata     oracle.sqldeveloper.migration.teradata     11.1.1.04.34     Loaded
    Oracle SQL Developer - Migrations Translation UI     oracle.sqldeveloper.migration.translation.gui     11.1.1.04.34     Loaded
    Oracle SQL Developer - Object Viewer     oracle.sqldeveloper.oviewer     11.1.1.04.34     Loaded
    Oracle SQL Developer - Real Time SQL Monitoring     oracle.sqldeveloper.sqlmonitor     11.1.1.04.34     Loaded
    Oracle SQL Developer - Reports     oracle.sqldeveloper.report     11.1.1.04.34     Loaded
    Oracle SQL Developer - Scheduler     oracle.sqldeveloper.scheduler     11.1.1.04.34     Loaded
    Oracle SQL Developer - Schema Browser     oracle.sqldeveloper.schemabrowser     11.1.1.04.34     Loaded
    Oracle SQL Developer - SearchBar     oracle.sqldeveloper.searchbar     11.1.1.04.34     Loaded
    Oracle SQL Developer - Snippet     oracle.sqldeveloper.snippet     11.1.1.04.34     Loaded
    Oracle SQL Developer - Spatial     oracle.sqldeveloper.spatial     11.1.1.04.34     Loaded
    Oracle SQL Developer - TimesTen     oracle.sqldeveloper.timesten     2.0.0.04.34     Loaded
    Oracle SQL Developer - Tuning     oracle.sqldeveloper.tuning     11.1.1.04.34     Loaded
    Oracle SQL Developer - Unit Test     oracle.sqldeveloper.unit_test     11.1.1.04.34     Loaded
    Oracle SQL Developer - User Extensions Support     oracle.sqldeveloper.userextensions     11.1.1.04.34     Loaded
    Oracle SQL Developer - Worksheet v2     oracle.sqldeveloper.worksheet     11.1.1.04.34     Loaded
    Oracle SQL Developer - XML Schema     oracle.sqldeveloper.xmlschema     11.1.1.04.34     Loaded
    Oracle SQL Developer Data Modeler     oracle.datamodeler     3.0.0.665.2     Loaded
    Oracle SQL Developer Data Modeler - Reports     oracle.sqldeveloper.datamodeler_reports     11.1.1.04.34     Loaded
    PROBE Debugger     oracle.jdeveloper.db.debug.probe     11.1.1.4.37.59.31     Loaded
    Peek     oracle.ide.peek     11.1.1.4.37.59.31     Loaded
    Persistent Storage     oracle.ide.persistence     11.1.1.4.37.59.31     Loaded
    Property Inspector     oracle.ide.inspector     11.1.1.4.37.59.31     Loaded
    QuickDiff     oracle.ide.quickdiff     11.1.1.4.37.59.31     Loaded
    Replace With     oracle.ide.replace     11.1.1.4.37.59.31     Loaded
    Runner     oracle.ide.runner     11.1.1.4.37.59.31     Loaded
    VHV     oracle.ide.vhv     11.1.1.4.37.59.31     Loaded
    Versioning Support     oracle.jdeveloper.vcs     11.1.1.4.37.59.31     Loaded
    Versioning Support for Subversion     oracle.jdeveloper.subversion     11.1.1.4.37.59.31     Loaded
    Virtual File System     oracle.ide.vfs     11.1.1.4.37.59.31     Loaded
    Web Browser and Proxy     oracle.ide.webbrowser     11.1.1.4.37.59.31     Loaded
    XML Editing Framework IDE Extension     oracle.ide.xmlef     11.1.1.4.37.59.31     Loaded
    audit     oracle.ide.audit     11.1.1.4.37.59.31     Loaded
    classpath: protocol handler extension     oracle.jdeveloper.classpath     11.1.1.0.0     Loaded
    jdukshare     oracle.bm.jdukshare     11.1.1.4.37.59.31     Loaded
    mof-xmi     oracle.mof.xmi     11.1.1.4.37.59.31     Loaded
    oracle.ide.dependency     oracle.ide.dependency     11.1.1.4.37.59.31     Loaded
    oracle.ide.indexing     oracle.ide.indexing     11.1.1.4.37.59.31     Loaded
    palette2     oracle.ide.palette2     11.1.1.4.37.59.31     Loaded
    status     oracle.ide.status     11.1.1.4.37.59.31     Loaded

    are you using an "Expert Mode" query or not?
    With normal mode, the query is stored in an XML attribute.
    With expert mode, it's stored in a CDATA Section, which allows it to respect all user-spacing and newlines.
    XML attribute values are forced by the XML 1.0 spec to be normalized, and this is done by the parser when they are read in. That might account for your different in space treatment.

  • How do I save/export as a TAB or SPACE delimited text file?

    Just upgraded from Apple Works to iWorks. The only text exporting option I see is .csv. Comma separation really screws up my needs. Is there a way to export as plain text? TAB or SPACE delimited?

    Why not using the good old
    --[SCRIPT clipboard2textFile]
    on run
    set tsv to the clipboard as text
    set nomDuFichier to (do shell script "date " & quote & "+P%Y%m%d-%H%M%S" & quote) & ".txt"
    set p2d to path to documents folder as text
    tell application "System Events"
    make new file at end of folder p2d with properties {name:nomDuFichier, file type:"TEXT"}
    end tell -- System Events
    set leDoc to p2d & nomDuFichier
    write tsv to file leDoc
    end run
    --[/SCRIPT]
    I have it installed as:
    <startupVolume>:Users:<my account>:Library:Scripts:clipboard2textFile.scpt
    No need for an extra application.
    Copy to clipboard,
    trigger the script from the menu,
    the text file is available on the desktop.
    Yvan KOENIG (VALLAURIS, France.) lundi 24 août 2009 16:25:13

  • [svn:fx-trunk] 11450: Cleaning up the whitespace in these 3 files ( tabs to spaces).

    Revision: 11450
    Author:   [email protected]
    Date:     2009-11-04 17:10:56 -0800 (Wed, 04 Nov 2009)
    Log Message:
    Cleaning up the whitespace in these 3 files (tabs to spaces).
    QE notes: No
    Doc notes: No
    Bugs: No
    Reviewer: Me
    Tests run: Checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Group.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/GroupBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/supportClasses/GraphicEleme nt.as

    Thats good news.

  • Remapping keys for Spaces

    How can I remap F5 and F6 to go to Space 1 and Space 2, respectively?
    I'm just starting to use Spaces. I'm a Final Cut Studio editor, and the ^/cmd/option-numpad keys are already reserved for other functions within my edit layout. On my keyboard, it looks like F5 and F6 aren't used. I would love to make use of those keys to shuttle me between space 1 and space 2. I tried going into SysPrefs > Keyboard&Mouse > Keyboard Shortcuts, but it's asking me for the specific menu item in spaces, and I don't know what they're called.
    Bonus question: How do I move FCP to another space without dragging each window one-by-one?
    Thanks en avance!

    I suggest just mapping FCP to a set space that you always use. In System Preferences you can set spaces up to have an app run in a specific space. The just select your app either from the dock or CMD + Tab to shift across to FCP.
    Bonus Answer... you can move everything in a space by opening spaces, clicking on a blank part of the space you want to move and dragging everything in that space to a new position. You'll move the entire space to a new position
    Message was edited by: sydneyfx

  • Double click in the empty tab bar space to open a new tab.

    I upgraded to Firefox 7 today, and now if I try to click in the empty space on the tab bar to the right of the current tabs I no longer get a new tab.
    Is there a way to re-enable this feature?

    Sorry but this is annoying! I have been using Firefox for a long time and all of a sudden an update (7.0) stops the doubleclick in the tabs bar.
    I have Firefox both at the office and at home. Strangely, at home I´ve got this problem but at the office I haven´t. I´ve got XP at the office and Vista at home.
    And please don´t tell me to get used to the plus button or the mouse middle button.

  • Command-tab Finder + Spaces nuttiness

    Hi Folks. New to Mac OS X Leopard (10.5.2) on a Macbook pro, coming from Windows XP. The command-tab switch feature on my Mac sometimes does something strange when Spaces is combined with multiple Finder windows, and I'd love to know how to make it work in a more intuitive manner.
    Please tell me if you've experienced this: Sometimes when I switch back and forth from an application (e.g., Firefox) to the Finder with command-tab, the Finder window switched to is different each time - it seems to cycle through each window in each space. The only work-around is to use command-` .
    Unfortunately, while writing detailed steps to recreate this, it went away. Drat!
    Anyone seen this? Thanks in advance!
    matt

    Hi Folks. New to Mac OS X Leopard (10.5.2) on a Macbook pro, coming from Windows XP. The command-tab switch feature on my Mac sometimes does something strange when Spaces is combined with multiple Finder windows, and I'd love to know how to make it work in a more intuitive manner.
    Please tell me if you've experienced this: Sometimes when I switch back and forth from an application (e.g., Firefox) to the Finder with command-tab, the Finder window switched to is different each time - it seems to cycle through each window in each space. The only work-around is to use command-` .
    Unfortunately, while writing detailed steps to recreate this, it went away. Drat!
    Anyone seen this? Thanks in advance!
    matt

  • Converting tabs to spaces

    Just so you all know, this is an assignment for school that I'm having trouble with.
    One of the parts of this assignment is to convert spaces to tabs in a text file. However, we have to maintain the original spacing (otherwise it would be simple). I'm honestly baffled as to how this can be accomplished. I hope I'm along the right lines in trying to use StringBuilder but I can't quite get the spacing to come out right. So my question is, how do I replace the spaces with tabs, but maintain the spacing of the original file.
    Here is my SSCCE
    import java.util.Scanner;
    import java.io.*;
    public class SpacesToTabs
         public static void main(String[] args)
              String line, fileName = null;
              StringBuilder sb = null;
              Scanner stdIn = new Scanner(System.in), in = null;
              BufferedWriter out = null;
              System.out.print("Enter filename[test.txt]: ");
              fileName = stdIn.nextLine();
              try
                   //In and Out objects
                   in = new Scanner(new BufferedReader(new FileReader(fileName)));
                   out = new BufferedWriter(new FileWriter(fileName.substring(0, fileName.indexOf('.')) + "_new" + fileName.substring(fileName.indexOf('.'), fileName.length())));
                   while(in.hasNext())
                        //Read a line
                        line = in.nextLine();
                        //Make a new StringBuilder
                        sb = new StringBuilder(line.length());
                        //Loop through that line
                        for(int i =0; i<line.length(); i++)
                             //If it's a space, replace it with a tab
                             //this is where I'm confused as to how I can maintain the spacing
                             if(line.charAt(i) == ' ')
                                  sb.insert(i, '\t');
                             else
                             //If not a space, just copy it
                                  sb.append(line.charAt(i));
                        //Write to the buffer
                        out.write(sb.toString());
                        out.newLine();
              catch(FileNotFoundException e)
                   System.err.println(e.getMessage());
              catch(IOException e)
                   System.err.println(e.getMessage());
              finally
                   try
                        //flush and close all streams
                        out.flush();
                        in.close();
                        out.close();
                   catch(IOException e)
                        System.err.println(e.getMessage());
    }And here is a test file (test.txt)
    blah blah blah line 1   tab
    blah blah blah line 2   tab
    blah blah blah line 3   tab
    blah blah blah line 4   tab
    t       tab     tab     tab

    Teacher wrote:
    My standard answer: You decide how many spaces = 1 tab for conversion purposes. If you want to substitute 4 space characters for one '\t', make it so (and vice versa, as well).Maybe I'm over thinking it. I wrote my teacher and this is how he replied. If you take that exactly at face value, then just replacing x amount of spaces with a tab is trivial. However, I'd like to keep working on my interpretation of the question as I think preservation of the spacing of the original document is important. Here is what I've managed to put together so far and the issues I'm having. The biggest problem I'm having at this stage is that the first character AFTER the spaces is getting eaten by the sb.replace call. I can't figure out why this is happening. If I reduce count by one (which should move back the substring being replaced by one character) then it STILL gets eaten and now there is a space after the tab. I've spent too long looking at this and I'm sure it's something simple I'm missing. I'll cool my brain for awhile and come back.
    P.S. Ignore the comments, they are diagnostic for me but I left them in in case anyone wanted to use them.
    //sb is a stringbuffer holding the current line read in from the file
                                           //We have to ignore spaces at the beginning of the line because 0 -1 causes index out of bounds error
                             if(i%8 == 0 && !(i==0) && line.charAt(i-1) == ' ')
                                  //System.out.println("Character at index " + (i-1) + " is a(n) |" + line.charAt(i-1) + "|");
                                                   //Start the index at the space character
                                  int index = i-1;
                                  int count = 0;
                                  //System.out.println("i="+i+"index="+index);
                                                   //go backwards, counting spaces, until we find how many
                                  while(line.charAt(index) == ' ')
                                       index--;
                                       count++;
                                       //System.out.println("Counting spaces! Index is now " + index + ", count is now " +count);
                                                   //increase index by one (If we don't do this, the last character before all the spaces gets eaten
                                  index++;
                                  //System.out.println("Replacing substring: |" +line.substring(index, index + count)+ "|\nStarting index: "+index+"\nEnding index: "+(index + count));
                                  sb.replace(index, index + count, "\t");
                             else
                             //If not a space, just copy it
                                  sb.append(line.charAt(i));

  • Expose, Cmd Tab, Screenshot, Spaces all breaking

    Not sure what causes this, I thought it was sleeping but apparently not.
    All Expose, Cmd Tab, Screenshot and Spaces will all be fine but they theyll stop working and I also cannot reboot or log out, the Mac just wont.
    I have to go Terminal -> "sudo reboot" to force a restart.

    Couple of possibilities. The first thing I'd try is clearing your launchServices caches.
    Launch Terminal and copy & paste this at the command line to rebuild LaunchServices:
    Code:
    <pre class="alt2" style="margin:0px; padding:3px; border:1px inset; width:640px; height:34px; overflow:auto">/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchSe rvices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user</pre>
    Then press return. Wait until terminal returns to the command line. Quit Terminal. After that, log out and back in or restart. Let us know
    -mj

  • Global site edit -- change tabs to spaces in DW

    Is there a way in DW to do a site-wide change that replaces
    all the tabs in the code with spaces? I know you can do it page by
    page, but I was hoping for a faster way.
    Thanks!

    Tabs in the code? You mean in Code view?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "isleta13" <[email protected]> wrote in
    message
    news:ehq595$c1e$[email protected]..
    > Is there a way in DW to do a site-wide change that
    replaces all the tabs
    > in the code with spaces? I know you can do it page by
    page, but I was
    > hoping for a faster way.
    >
    > Thanks!

  • Faulty keyboard(Tab, delete, space etc)

    Hi!
    I am new to this forum. Usually when I have a problem with my mac, I just google it. But this time I really cant find anything. When I am writing this question, I have had to paste every god-damned space in the text.
    This is because all of a sudden certain buttons on my keyboard(The built-in on my mb pro) have stopped responding. This includes spacebar, left- and down-arrow, backspace, caps-lock, tab and a couple of others. But none of the letters. I am positive that nothing has been spilled, nothing has been broken. I am about to go nuts. It has been like yhis for almost a week, becaiuse I havent had time to check it out(Other than google the s* out of google) have never had any other serious problems with my mac, and it has been treated well. I am hoping there is another way than sending it in to Apple for a repair.
    OS is 10.6.4 and my Macbook pro 15" is a little over a year.
    Pleaase help! (Please)

    Unfortunately, in my experience this is one of two possible problems.
    1: Bad top case (very likely)
    2: Bad logic board
    This COULD also be the result of an expanding battery, and a loose connector, but they seem a bit unlikely.
    Considering how easy it is to break the locking levers on the connectors, and the fact that it requires a new logic board to fix, I'll just suggest skipping that.
    If you see signs of the battery expanding, then take it somewhere to have the battery removed. The 15" models are locked in with a special screw you will absolutely not find anywhere. I looked long, and I looked hard, but ultimately had to get one from Apple (which I can do because I work for an AASP). It'll be up to you if you want to replace the battery or not.
    The top case seems to be the most likely cause however. And on unibody systems this means they have to disassemble the entire system. With the unibody systems, the top case is now the base component which everything else is built around.
    So, sorry to say, you probably will have to send it to Apple. Or at least leave it at an AASP/Apple store.

  • Have upgrade for CS4 & CS5 Is "tab" & overlapping spaces fixed?

    I just started working with CS4 and haven't installed 5. I can't stand the new interface with the tabs. Unchecking the box to revert to floating windows doesn't work and everytime I open a file it reverts to tabs. Even when I've selected floating windows in the workflow, it needs to be reselected every time I load a new file to add to my project. Not to mention the new windows covering all the menu/tool/pref boxes.
    My question, is this fixed later in a 4 update or in 5?
    If not, can anyone refer me to a decent Mac photo editor that may lack some of photoshop's features but will work with layers and a few of the less powerful features? I'm asking this seriously. I'm ready to list my photoshop license (with a legit transfer) on ebay. Would like your opinion as to subsitutes on the Mac...even on Windows. I'd even switch to windows to be done with this mess Adobe has turned a great program into. I'm not a professional and don't need this hassel in my life.
    Please no flames. I'm not trying to start a war. Just thoughtful considerate replies?
    Thanks.

    Have you turned both relevant preferences off?
    Edit:

  • How do i split content from the text file using tab and spaces...?

    Hi.. Just want to ask help to all the experts. Im new in java and i have this problem on how to split the contents of the text file. ill show you the contents in order to let you see what i mean.
    FileName: COL.txt
    AcctNo AcctName Primary Secondary Status Opendate
    121244 IPI Company Noel Jose Active 12/05/2007
    As you can see the content i want to split it per column.. Please help me

    Jose_Noel wrote:
    Hi prometheuzz,
    What do you mean by one thread...?You created two threads* with the same question in it. That way, people might end up giving you an answer that has already been posted in your other thread: thus wasting that person's time.
    Just don't create multiple threads with the same question please.
    * a thread is a post here at the forum

  • Command-tab, screenshot, spaces functions missing.

    This occurs in tandem with a menu bar situation where the spotlight and bluetooth icon and one or two icons on the far left appear, but not the time, sound, monitor wireless etc.
    Also I have to force quit everything and restart won't work so i have to hlld the power button down to shut the mini off.
    Restarting usually helps
    I'm running 10.5.6 on a 1.42 mini.

    This occurs in tandem with a menu bar situation where the spotlight and bluetooth icon and one or two icons on the far left appear, but not the time, sound, monitor wireless etc.
    Also I have to force quit everything and restart won't work so i have to hlld the power button down to shut the mini off.
    Restarting usually helps
    I'm running 10.5.6 on a 1.42 mini.

  • How to convert tabs between the words in a String to a single space in java

    I have a string with more number of tabs in between them, the thing I need to do is that I need to convert all those tabs into a single space.
    I used replaceAll(“/t”,” “); but the problem is that it was converting the tabs into spaces but if we have a 3 tabs in between 2 words then this 3 tabs are converting into 3 spaces but I need to have only one space.

    user548049,
    How is your question related to the topic of this forum: Oracle Database-embedded JVM?
    Anyway, you need to use the greedy qualifier: +, like so:
    replaceAll("\\t+"," ")Good Luck,
    Avi.

Maybe you are looking for

  • Reporting point problem

    Hi all, I have a problem with reporting in SCCM2012 SP1. SCCM farm contains two servers: Primary server and database server. I have added reporting services point on database server with SQL 2012 to different reporting instance (default instance is u

  • Dragging images from Safari to Desktop, image goes to random location

    Hi Everyone, Problem is being experienced on a Retina MBP, in a laptop-screen + 2 more setup: one through Thunderbolt to DVI, and the other using HDMI to DVI. It's pretty easy to reproduce.  I open Safari up, not fullscreen, and drag an image that's

  • Landed Costs Journal Entry

    My customer created a Purchase Order, then a GRPO based on the PO.(both in USD) for different items of different item groups. They then created Landed Costs based on the GRPO in ZAR. The journal created the following transactions : Item Group A to Pr

  • USER EXIT CODE In BEX

    Friends, In Bex query for an ODS,I need to create a report -In the selection screen user has to enter one date value.(DATE1 Varible) I need to get the values in the report based on following condition ==>DATE1 < DATE2. As user defined variable can be

  • SS2K_SYSLOGINS ORA-01401 using WB for SQL server 2000

    Hi there, I've read some threads on this issue on this forum but no solution to be found. I noticed that the NAME field on the table SS2K_SYSLOGINS has been declared as varchar2(30) and is reading the SYSLOGINS views column NAME ( as declared sysname