I'm building a grammatical text interpreter with a JavaFX GUI where you can just paste your text into a TextArea. This creates something of a problem though, since line breaks from MS Word are somehow formatted in a special way (both paragraphs (ENTER) and line breaks (SHIFT+ENTER).
If I copy the text to a plain .txt file and open it in a browser (tried Chrome, Safari and Firefox), I can copy it again from there without any problem. They somehow fix the issue.
Pasting the text into a new e-mail in Apple's mail and then copying it from there, fixes it, even pasting it into a JEditorPane (java swing), fixes it.
Notepad, TextEdit, Notes and Pages does NOT solve it.
But I need the ability to copy the text directly from a variety of sources and asking people to copy it to somewhere else is just not an option.
I searched for a solution before this post, and the general solution I could find was to replace "\r" with "\r\n", but this doesn't seem to help, as the line break is already lost, as soon as it has been pasted into the TextArea.
A different solution would of course be to simply use a JEditorPane instead of the TextArea, but when I create an AnchorPane and put a JEditorPane into it as a swingComponent, I get an area the size of the initial text, and editing that text on runtime doesn't change the size of that area (which is NOT the area of the contentPane).
Now, I know that I present different solution ideas here, and that I probably should just ask for how to get one specific thing to work, but I'm really getting a headache over this, so weather it's a way to get the contentPane to work properly with the layout, finding a way to make the TextArea keep these linebreaks or even something different is fine. I've just spent too much time trying to solve it now :(
Related
Let me start off with saying that I've seen some questions in this regard but nothing actually specifically answering my issue.
Let's say I have a template version of a PDF received by someone else. It's a classic PDF that looks like a form but only one part is editable, the other parts are not because they are being filled in with data from an imported excel sheet. (Sadly I can't show an example)
I've been able to do most in iText 7 but I can't figure out for the life of me if I can change a flat text field into an editable form field, like on image 1.
Image 2 shows checkboxes that I want to make editable as well but I can only change their value within java and even then it only shows a cross, not a checkmark (even if I change the checktype).
It's a bit hard to explain but tl:dr is that I just want to know whether I can edit an existing flat PDF in java or if I have to do so in adobe itself.
Thanks
I followed the OCR text reader guide on Codelabs (https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#0).
Now, I would like to save, a single portion of the text that I am scanning.
I tried with reducing width, and height of the preview; but it doesn't work, the APK crashes (at least on the only device I have to test it).
I am completely new to Java, and Android development, but my Internship mentor said to do this; completely alone, with zero help (as no one in the company knows about development).
So, the app opens, it recognizes text. Now, I would like to to know if there is a way to take that text, and save it (XML or TXT file).
I tried to look in the code, and see if at some point, the text read is saved in a variable or something; but it looks like a live preview, done trough the Google's dependencies (or a similar process).
I am not sure, but this might be off topic, as it is similar to an open question, but I am giving details on what I have done so far, and what I have tried.
Thanks.
The detected text is displayed in the OcrGraphic.draw(Canvas) method. There, it is returned as a TextBlock. You can call textBlock.getComponents() to get the lines and textBlock.getComponents() again to get each individual word (as a Text object).
Then you can convert it to a string and write the text to a file if you would like.
We have a requirement where we already have pre printed stationery and want user to put data in a HTML form and be able to print data on that form. Alignment/text size etc are very important since the pre-printed stationery already has boxes for each character. What could be a good way to achieve this in java? I have thinking of using jasper reports. Any other options? May be overlay image with text or something?
Also we might need to capability to print on plain paper in which case the boxes needs to be printed by our application and the form should match after the printed with the already printed blank stationery containing data.
Do we have some open source framework to do such stuff?
Jaspersoft reports -- http://sourceforge.net/projects/jasperreports/
You will then create XML templates, then you will be able to produce a report in PDF, HTML, CSV, XLS, TXT, RTF, and more. It has all the necessary options to customize the report. Used it before and recommend it.
You will create the templates with iReport then write the code for the engine to pass the data in different possible ways.
check http://www.jaspersoft.com/jasperreports
Edit:
You can have background images and overlay the boxes over it and set a limit on the max character size ... and many more
It is very powerful and gives you plenty of options
Here is one of iReport's tutorial for a background image http://ireport-tutorial.blogspot.com/2008/12/background-image-in-ireport.html
The big problem when printing form content that has been filled in electronically, is aligning it correctly on the pre-printed form. You may get content to align for one printer, but when you use another it is completely misaligned.
Fly Software have a form design product called InForm Designer that gets around the problem nicely by allowing users to specify and save vertical and horizontal offsets for printers. This ensures filled in form content is always aligned. I've tried it and it works perfectly. Take a look for yourself here...
http://www.flysoftware.com/products/inform_designer/overview.asp
It might be worth implementing a printer offset similar to InForm's in your own application (if possible).
Some things to think about.
First in terms of the web page, do you want use the stationery as the form layout?
Does it have to be exact?
Combed boxes (one for each character)
Do you want to show it like that on the web page, or deal with the combing later.
How are you going to deal with say a combed 6 digit number. Is this right aligned. What if they enter 7 digits. Same for text. what if it won't fit.
Font choices, we had a lot of fun with W...
How aligned do you want the character within the box, what font limitations does that imply, some of the auto magic software we looked at did crap like change the size of each character.
Combed editing is a nightmare, we display combed, but raise an edit surface the size of the full box on selection.
Another thing that might drive you barking mad, you find find small differences in the size and layout of the boxes, so they look okay from a distance but a column of boxes sort of shifts about by a pixel. Some of testing guys had to lend us their electron microscopes, so we could see how many ink molecules we were out by. :(
Expect to spend a lot of time in the UI side of things, and remember printed stationery changes, so giving yourself some sort of meta description of the form to start with will save you loads of trouble later on.
I am a huge newbie and I have a program that normally prints items to the Java console window. I would like this program to become a window in which the user can interact with. The reason why I have not resorted to dialog boxes and panels is because this program require multiple prints to the console window. A traditional dialog box does not continuously update or compound on data that has already been printed on the box. I realize that there is another way of doing this by creating a program that mimics the Java console window. Because I am a noob, all of the java console redirecting questions and answers on this site have blown over my head. Can anyone please help me?
See maybe How to Use Editor Panes and Text Panes will be helpful and give you some ideas.
The short answer is, every time you want to update the contents of a text box, call the setText function again. There's no "append" function on the contents: you have to give the entire contents each time. If you want something that mimics a console window, where messages continue to scroll, the simplest thing to do is to keep the entire contents in a StringBuilder. Each time you get new text append to the StringBuilder, then setText(myStringBuilder.toString).
You could, I supppose, write mybox.setText(mybox.getText()+"new contents"). That would be a little inefficient but probably not a big deal.
I don't know exactly what you're up to, but trying to redirect console output to a text box sounds like more nuisance that it's worth. Just put your data in the text box: don't write it somewhere else, then try to get it back and put it where you want it. I suppose if you have thousands of lines of code writing to the console and now you want it to go a text box, there might be value in not having to change all that code. But the structure of a console app is so different from the structure of a GUI app that changing the output statements would probably be the least of the things you'd have to rework.
I'm looking for a highly efficient Swing Java component which I can just plug into my application UI. I already tried using the classes within Swing such as JTextArea with no avail; they simply aren't high-performance enough and have any crippling drawbacks. Additionally, it'd be nice if it had standard console features such as scroll-lock, clear console, colours, and so on.
Edit: Forgot to say, this console will have a lot of debug information streaming into it, and it needs to be fully scrollable.
Cheers,
Chris
I fail to see what is wrong with using a JTextPane. It supports attributes which you can specify as each piece of text is added to the console. Clearing it is also obviously a no brainer. When added to a scroll pane it also supports scrolling.
You can add scroll locking by using Smart Scrolling.
Plus, it removes text too early and
No idea what that means as text is never removed unless you specifically remove it from the document.
doesn't allow the user to scroll while
input is being entered (afaik). The
effect is that you just see text
flashing while the number of rows
remains the same.
By default the text scrolls automatically as text is append to the document assuming the code is executed on the EDT. This scrolling can be controlled the the example provided in the link above.
Edit:
but I'd still like a library solution
I don't know of any
auto-colourise text coming from
different streams
The Message Console might give you some ideas.
(i.e., detect [error] prefix on a
line) and colourise lines based on
this)
This is easily done by adding a DocumentFilter to the Document of the text pane. You can add attributes as text is inserted into the Document.
Be sure that you read about the Event Dispatching Thread (EDT) in swing!
BTW: a simple search 'java swing console' will give you a lots of hints OR you could use/adapt the beanshell textfield which is a jtextfield too ...