As you can see, after every text comes a tab, everything is working fine, but after third tab (see output) it generates a space not a tab.
fileWriter = new FileWriter(indexFile, true);
fileWriter.append(id).append("\t");
fileWriter.append(String.valueOf(idx)).append("\t");
fileWriter.append(String.valueOf(pageCount)).append("\t");
fileWriter.append(postal.toUpperCase()).append("\t"); <-- this one
fileWriter.append(address.toUpperCase());
fileWriter.append("\r\n");
My output:
00000347 1 1 FB-6666 DUMMY STREET 1 LAT
The problem comes after "FB-6666".
Any ideas on this?
No, it really is generating a tab - it's just that whatever you're using to view the file is deciding to handle tabs by aligning them to some boundary or other. If you make your postal value FB-6666x I suspect you'll then see a much larger space.
This isn't a problem with the file content at all.
If you want to enforce a certain number of spaces between columns, you'll need to write that many spaces. Alternatively, something else to view the file...
Tabstops don't work this way. As the wikipedia article states,
Tab stops are set manually, and pressing the tab key causes the carriage to go to the next tab stop. In text editors on a computer, the same concept is implemented simplistically with automatic, fixed tab stops.
This means the tabstop will stop at a predefined position in the textfile, not after let's say the space it would take to insert a specific amount of spaces.
It is writing a tab I promise - to convince yourself of this you should either open the resulting file in a hex editor and look at the value in that position, or add another character to the value before the tab and see how the format of the output changes.
Related
While debugging Java code, Strings in the views "Variables" and "Expressions" show up only till a certain length, after which Eclipse shows "..."
Is there any way to inspect the entire string? (This eases the pain of adding logging statements for debugging everywhere)
In the Variables view you can right click on Details pane (the section where the string content is displayed) and select "Max Length..." popup menu. The same length applies to expression inspector popup and few other places.
In the Variables view you right-click on the variable and select Change value. If your variable is huge you have to wait a few minutes (in this case Eclipse doesn't respond to commands) but in the end Eclipse will show your variable entirely.
If you have a really long string, I use a different strategy: dump it to a file. I have a snippet of code I use in the Display view, which is evaluated to dump the data to a file. I use Commons IO, but you can do it with JDK only methods.
org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File("<filename>"), <expression to evaluate>);
Naturally, you will need the Commons IO JAR in your classpath for that to work. If you don't, resort to JDK work.
The best way to view a String value from eclipse debug view is as below.
1) Switch to debug view in Eclipse
2) Select the desired variable in variable pane.
3) Right click on display area of variable pane where value is shown and click on Max Length. Enter the maximum char value in Configure Details Pane .
4) Cheers
When debugger reaches the point where you want the String value, just type a sysOut statement
System.out.println("The value is : \n " + query);
Select the above the statement, right click-> Execute
It will print the value on the console
For javascript based debugging on eclipse, "change value" method and "Max length" method both failed for me, adding the required object to watch(Expressions) and then Right Clicking the watched expression to select "Load Full Value" is the only solution that works for me, but even this inserts unwanted "\n" in the output.
Note - "Max length" must be set for the "Load Full Value" to work as it loads values till max length(default in eclipse is 10000). Refer above answer to see how to set Max length.
There is no "maxLength" in Eclipse Mars. And, the "change value" only works with "Variables", not "Expressions", so none of above works for me.
And, the expression are cut in the middle, not at the end. I guess they changed the default behaviour.
The only thing working for me, is to expand the expression name column's width, and click the expression to select it all to see the full length content.
Nothing from the above worked for me, moreover, some user interface elements in my Eclipse can not be found as described. I'm using STS 4.3.1.
The value I needed was really big, it is part of a huge JSON request. Workaround is to use an expression in Eclipse Debug Shell console and to output the substring of the whole value. Since you can see the partial value, inspect it and use the last few literals as the position to output the next chunk of the string. Repeat this approach until get what you need:
String result = new String(reallyBigByteArrayValue, "UTF-8");
result.substring(result.indexOf("some-unique-text"));
In Eclipse IDE 2020-09 it's "Pretty print to console" on right click.
From the console the copying is possible at full length.
I have a table of forms which accepts first name, last name etc. When I navigate through using the tab key and enter some text in first name, all of the text disappears and that row gets selected. I have tried almost all techniques.
Is there any way we can avoid that using coding?
If I use the mouse then it wont give that error.
Assuming an otherwise correct use of JTable, you may need to terminate the edit when focus is lost, as suggested here and here:
table.putClientProperty("terminateEditOnFocusLost", true);
I'm having a problem with JTextArea (not a problem though).
I want to create my own college program, one of the function is to write down and save a list of homework each day. It's text area having the main function here, which is to type everything my lecturer said. But text area will act like Windows original notepad, which is not keeping the indentation. So my questions are:
How do I have a function where I press the SHIFT+TAB key it will decrease indentation by one.
If number 1 is possible, then how do my program have behaviour when I press ENTER key, it will have a new line with previous indentation? Just like NetBeans and other IDE.
Edited: I'm a beginner in Java, in truth, I'm making this program while studying Java in my college.
How do I have a function where I press the SHIFT+TAB key it will decrease indentation by one.
You need to use key bindings to listen for the user typing Shift+Tab.
If number 1 is possible, then how do my program have behavior when I press ENTER key, it will have a new line with previous indentation? Just like NetBeans and other IDE.
Use a similar piece of logic to capture the Enter key presses. Then, check the previous line in the editor and count the number of tab characters preceding the text. Output a similar number at the start of the new line.
you could use Javascript/jquery for indenting by inserting empty space of specific line. while pressing your hot key combination call function to insert five spaces on your cursor.
everybody. I have completed my code two txt files by showing on the same area.
but I want to compare two txt files line by line. and I want to show the differences with Colored lines and finally, The letter or words that are different, different line I'm going to bold.
how can i start?
thanks for now, my code is here.
JTextArea might make a suitable view, but you still need to model the differences. I'd look at the Eclipse or NetBeans platforms, or perhaps svnview.
You might need to ask user to upload both versions of file.
In the server you need to compare line by line, and store the line numbers of the file differences in another file or location
Then, while displaying, get the line numbers and give them proper decoration (i.e bold etc.).
is it possible, in Eclipse, to mark certain lines with Shortcuts and be able to quickly jump to those lines?
Example: Let's say I have maintenanceHeavyMethod() at line 120 in my class, gameLoop() at line 800 and some listener at line 1460.
I'd like to f.ex. press CTRL+SHIFT+1, 2, 3 etc. to mark those positions, and then use f.ex. CTRL+1, 2, 3 to immediately jump to them. I don't like split-screens etc, but I need to jump around when writing.
Is there such a feature?
I'm using latest Eclipse to write Java-programs.
You can add Bookmarks in your code. Select the code fragment you want to bookmark and then go to Edit > Add Bookmark... (also possible via the menu available with a right-click in the left hand column of the editor, like breakpoints).
Then, add the Bookmarks view. Select Window > Show View > Other... > Bookmarks and you'll get something like this:
Sadly, I don't think you can bind a shortcut to a particular bookmark.
Just in case, the shortcut to jump to a particular line is CTRL+L.
That would be best taken care by mylyn:
Define a task with this three method, and you will be to see only those 3 in the package explorer view
To jump to a particular method, I use ctrl+o and then start typing the method. If you're a proficient typist, this shouldn't take any longer; keep in mind that you only have to start typing the name of the method.
Unfortunately this isn't a proper solution for jumping to a line of code within a method.
You can jump to methods by using the outline view. Outline view shows all the Methods, Fields, and Inner-Classes (and their methods and fields and inner-classes...etc) of the source file you currently have open. I personally prefer this method, unless I have a stacktrace and know which line I want to jump to, in which case I use ctrl+L.