Render text on window 10 screen without JFrame in Java - java

Well I need to show text messages directly on the screen.
I tried searching a lot but found nothing that could solve my problem.
The options I found on the interner:
To use a JFrame and render text on that.
To print text on a console.
But the problems with these here I do not want any window to pop up.
I also want the text to be on top of all.
My attempt:
As far as my tries here it is :
Here is what it should look like:
As you can see my try is far from what I want.
Well is there a better way? Is it possible Without any Frames?
Well this could be similar to Toast messages in Android.

I did achieve what I intended.
Here is the link to the GitHub Repository : https://github.com/Jaysmitio101/jsubs
This is a Java Library for showing subtitles on any screen and also show messages like Toast messages in android.

Related

Is there a method to hide a JFrame from Print-Screen or Screen Recording?

I'm developing a virtual keyboard and would like to know what is the best approach to hide it from print-screen and screen recording.
I've found examples while researching the web, but the results are for Android - even if I put JFrame as a must have on the search query. Mostly, what I have found is something like: getWindow().WindowManager.LayoutParams.FLAG_SECURE - but like I said, it doesn't seems to be applicable for a desktop environment Java application (I think).
Thanks in advance for your for the help!
All my attempts were relying on "half measures" like creating a ClipboardMonitor (java.util.Observable, etc) - but this just gets me to avoid print-screens by flushing the clipboard.
What I'm aiming for is to hide the JFrame or make it black if a user tries to capture the screen with a print-screen command, a snip or screen record application.

JDialog onTop overlapped by another in a strange way

I am developing a Swing application with custom CSS rendering. As part of the system I use JDialogs as well, but I need to access certain components outside of the dialog (emergency buttons).
For this I chose following method:
all dialogs are non-modal. Those I want to make quasi-modal, will be setAlwaysOnTop.
There is always one quasi modal dialog up. In this case I put another dialog up, below this one, full-screen, semi-permanent.
This "blur" dialog shall cover the whole screen, catch mouse events and forward them to the emergency buttons only. In parallel I opened gaps on it so that the emergency buttons can be seen through the semipermanent surface without any effect.
The blur dialog can never be focused or activated (I have a vetoable listener for this)
Everything works fine, until someting happens and the blur dialog seems to cover my quasi-modal dialog. However, if I move any external application window over it, the quasi-modal dialog remains on the top. Instead of a complicated explanation, see picture un following link: http://lost.lost.hu/javascreen.png
So far I tried to debug repaints, events, everything, and could not find anything that would cause this. Especially the case depicted above challenges me to understand what is going on here.
I have recently updated to Java 1.7, in hope to get rid of this phenomenon, but today it came back.

How to copy text from a browser with Java?

Is there a way to copy text from a browser to my Java app ?
For example, at the left side of my screen I open a browser to point to a URL and shows the content of that page, it might be in a frame or CSS or simple html, on the right side of the screen I open a Java Swing application. I'm interested in certain parts of the browser window that shows some text, and I want my Java app [ without me doing anything ] to copy and paste the text into itself, can it be done ?
I know I can use JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane, but if the page uses Frames or some other complex ways, the text I get from the Pane is not what I see on the page, so I don't want to do it by loading the URL into my Java app, instead, I wonder if it can be done in the way I mentioned above ?
I think you're looking at the problem from the wrong angle. If what you want is to harvest a website, I suggest you have a look at the awesome library web-harvest. With a little Xpath wizardry you can get everything you want.
Doing what you describe would imply inter-process communication that seems like an overkill. There are more ways to download a web-page content than the browser.
You may try the following depending on your needs.
With java.awt.Robot you can either 1) Take an screenshot if what you neeed is the content ( without the text, just an image of the browser content ) or 2) Move your self into the browser and programatically press: CTRL-A + CTRL-C and return back to your swing app focus and programatically press: CTRL-V ( or CMD or whatever makes sense in your OS )
But again, this might or not work, depending on what you need.
I know a tool but i am not sure it meet your needs. Have you heard about selenium? http://seleniumhq.org/ It can replicate actions taken by the user in a browser and then manipulate them ussing java code. Have a look at the link it may be handy.
Using java.awt.Robot & a TextField will get the job done, not sure if there is any other way. Have robot press ctrl+a then ctrl+c, bring TextField into focus, and finally have robot press ctrl+v. Now from here you can create a button.setOnAction to save the TextField text into a string. Or you can use a change listener on the TextField setOnKeyReleased to do the same.

+Android Webview - how to autoscroll a page?

I'd like to open a html-page in a webview and make it auto-scroll downwards automatically in accordance with an interval set through a timer.
Although below example is for desktop, this link should give you an idea what I want to achieve (enable autoscrolling in the upper right part of the page):
example
First I thought about opening a webpage and then use some kind of code which would simulate/trigger DPAD-down (or Arrow-down). In Windows Mobile, I believe there was something called SendKeys but I couldn't find something similar in the Android-SDK (except for a test-SDK which I doubt I could use for publishing my app in AndroidMarket) so I guess the way mentioned above is not possible.
Another solution could perhaps be a java-script but the webpages are not created by me so I can't insert any anchor.
However, I noted that Webview has some methods called PageDown (and PageUp) which could also be a solution but I am afraid a PageDown would be too much for scrolling the way I want. I want the scrolling to be slow and smooth, more like a line at a time.
Do you have any ideas how I could implement this? I'd really appreciate your help.
You could try using,
View.scrollBy(int x, int y) to scroll the WebView.Use:
computeVerticalScrollOffset(),
computeVerticalScrollExtent() computeVerticalScrollRange() to calculate a maximum y value.

How to display image in Swing? in textarea?

I am creating a chat application using JApplet. I have a TextArea where all chat messages go. Everything in working fine and smooth just as you would expect a basic chat application to do. Now i want to add support for gestures. I wanted to know, how can we show an icon in TextArea? it only takes string in append() method.
You should probably be looking at JTextPane instead of JTextArea.
Have a look at this tutorial which among other things, gives this demo:

Categories