JTextArea appending and deleting problems - append

I have a jTextArea that displays the clicked item from a jTable. I have a running code already and I am able to display the strings into my jTextArea. However, I have an issue whenever I try to remove a string.
So far, below is my code for getting the string value from the clicked item in jTable:
c = jTable2.getModel().getValueAt(jTable2.convertRowIndexToModel(selectedRow), 1).toString(); // this will get the name of product from a table and store it into C variable
The string from above code will be displayed on my jTextArea, as shown below:
jTextArea1.append(c + "\n");
Now, whenever I click an item to my jTable this will be stored into c variable, and the new item will be appended on my jTextArea with next line.
My sample output in jTextArea of this will be:
Apple
Mango
Now, I want to delete a specific string from that jTextArea, which I am able to do so in my current code. I am using this line of code to do that:
jTextArea1.setText(jTextArea1.getText().replaceAll(c, ""));
But then, whenever I clicked my jTable once again to append a new item, it will be appended next to the empty string, sample output is like this:
// from here is the beginning of the jTextArea
Mango
Apple
Now, I got empty strings before the new text is displayed.
In conclusion, I have understood that I never deleted an item from my jTextArea, but what it did was only to replace the string into an empty one. My problem is that I want to be able to append a string, then delete it whenever I need to do so without affecting the other appended strings, and without having an empty string.
Is there any other way to achieve this in replacement of my "replaceAll" line of code?

What you are asking for is analogous to editing a line of text to delete something in the middle. Naturally, you usually do not want a gap. One way to do this would be to copy the line over character by character but with a rule that if a space was preceded by a space it will not be copied (or, if a space comes up and is copied, then only characters will be copied that are not a space in that instance).
You could copy a series of records by reading each string, checking whether it had only spaces in it, and adding that string to the second screen only if it was other than white space.

Related

Monaco editor: Replace short text with longer text

I want to use the additionalTextEdits of the autocomplete callback to replace some text.
In some cases, I want to replace a short text with a longer text and expect everything after the short text to get pushed further back.
Example:
Original: abde
Text to insert: ABC, startColumn: 1, endColumn: 3
Expected outcome: ABCde
Actual outcome: ABde
My suspicion is that the editor sees that I want to replace two characters and therefore only takes the first two characters of my provided text.
Is there a way to tell it to replace those two characters with the provided three characters and everything afterwards gets pushed one column back?
Here is the link to the documentation of the property that I use:
https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.CompletionItem.html#additionalTextEdits

How can I automatically delete dates and times in rows with EmEditor?

I have a text file.
There are hundreds of different filenames in the text file.
However, it says different date and time at the end of each file.
Sample: life-in-cosmos-2021-11-11-12-45-46 or life-in-cosmos-2021-11-11-12-45.
In order to change the names of the files in bulk, I first need to delete the dates in this text file.
So I want to automatically delete the dates and times in each row.
However, I don't know anything about this.
And I don't know how to use macros.
Therefore, if there is a solution for this, can you provide an answer with a picture or video?
In order to explain my request more clearly, I present 2 examples.
Example:
Original Text: cosmos-lights-colors-T5DAPC-2020-09-11
The result I want to do: cosmos-lights-colors-T5DAPC
Example 2:
Original Text: cosmos-lights-colors-T5DAPC-2021-04-02-12-37-49-utc
The result I want to do: cosmos-lights-colors-T5DAPC
Assuming a date is always at end of each line, you can replace a regular expression with an empty string. To do this:
Press Ctrl+H to bring up the Replace dialog box, and set following options:
Find: -[0-9]{4}-[0-9]{2}-[0-9]{2}[0-9\-]*?(\-utc){0,1}$
Replace with: (blank)
Set the Regular Expressions option
First, click the Find Next button to highlight matches to make sure they are correct. If the matches are incorrect, you will need to adjust the regular expression.
Finally, click the Replace All button to remove all matched strings.
Before replace
cosmos-lights-colors-T5DAPC-2020-09-11
cosmos-lights-colors-T5DAPC-2021-04-02-12-37-49-utc
After replace
cosmos-lights-colors-T5DAPC
cosmos-lights-colors-T5DAPC

Is there a function or a method to add " , " after every row in VSC?

I have a .json file which is about 600+ lines and it looks like this:
{data0..}
{data1..}
{data2..}
To use it i need to add [ before and ] after to make it an array (no problem)
but i need to add " , " after every row. Is there a function/method to do that faster than manual typing?
Every object contain data in it.
Or anything to make it readble?
Alternatively, and simpler,
Ctrl-A to select all.
Shift-All-I to put a cursor at each line end.
Type your ,.
Press Ctrl-H for the Search-Replace window
In the first line type \n which means new line and make sure the regular expressions button is pushed - it's 3rd in the row and looks like this: .*
In the second line type ,\n - to replace new line with a comma followed by a new line
Push the "replace all" button
Notice: it assumes every JSON object occupies strictly single line

Put graphics behind the text in the same window of SapScript

I need to put a .bmp of a stamp behind some text in a sapscript form - in one window.
I've uploaded the bitmap of the stamp by using the se78, I uploaded it as standard text.
I'm already done some testing. This is what I got so far:
/: INCLUDE Z_ADRS_SIGN_CN30 OBJECT TEXT ID ADRS LANGUAGE EN
/: INCLUDE 'Z_SIGN_STAMP_CN30' OBJECT TEXT ID ST LANGUAGE EN
This is working, but the stamp gets printed under the text.
If I switch the code-lines, the stamp gets printed above the text.
Now to my question: Is there a way to print the stamp behind the text in one window ? And if yes, how?
It can be done, but it's better to use SmartForms for this, because it can print watermarks natively.
For SapScript:
Create SO10 text element and insert graphics object there
Put this statement into your text element
BITMAP 'YOURBMP' OBJECT GRAPHICS ID BMAP TYPE BCOL.
In the MAIN window of your form put these statements
INCLUDE BMP OBJECT TEXT ID ST.
NEW-WINDOW.
The key point here is NEW-WINDOW statement. It opens new window oon the page explicitly and prints all consecutive SapScript statements in the new window.

Does Eclipse have a shortcut to split a line and introduce a variable?

During typing in code, I often have code lines that become long:
String result = new MyObject(foo, bar).getBaz().getFoo(new Config(new File(f))).get(key).get(0);
I frequently break up such a line manually, making two of them:
Foo foo = new MyObject(foo, bar).getBaz().getFoo(new Config(new File(f)));
String result = foo.get(key).get(0);
This means positioning the cursor after new File(f))), pressing Enter, then select the String result = part, cut and paste it from the first to the second line, create a new variable named like the getter, type it in at the beginning of the second line and at the beginning of the first line, the latter as an assignment, with declaration. A lot of manual typework if you do it often enaugh.
I wonder again and again if there is a help, like a keyboard short cut, which does this for me: I position the cursor after new File(f))), press Ctrl+something and the result is the two lines. A second one I wonder if it exists is if I would position the cursor on Config at the first line, Ctrl+something and it would form these lines:
Config config = new Config(new File(f));
String result = new MyObject(foo, bar).getBaz().getFoo(config).get(key).get(0);
I finally found it. Long version:
Position the cursor as described in the question, press Shift+Alt+L. A dialog will appear to configure the variable name, whether all occurrences shall be replaced or the variable should be declared final. Press Enter as you aggree to the settings.
Short version:
Position the cursor as described in the question, press Ctrl+1 and the quick fix menu will appear (even if there is nothing marked red or yellow). Select Extract to local variable (or one of the related options, as you need) and press Enter.
For the second example to work, the cursor must be positioned either after the expression you want to cut out
….getBaz().getFoo(new Config(new File(f))<CURSOR HERE>).get(key).get(0);
or on the new keyword.