I want to display strings randomly directly to the screen in any notebook/PC, showing each string for less than one second, but when I use System.out.println("My text here") in Java it opens in windows console output. How can I change the code to run a "java myfile.jar" so that it runs directly in Windows screen ?
Asked
Active
Viewed 115 times
2
-
You can use Java with Swing, Java FX - that way to make windows operation – Jacek Cz Aug 15 '17 at 14:09
-
If you don't want to get into JavaFX, look into the older system of Swing perhaps, and here specifically you may want JOptionPane. – Tim M. Aug 15 '17 at 14:43
-
You could take a look at this [wumpus example](https://stackoverflow.com/questions/24320014/how-to-call-launch-more-than-once-in-java) which displays pop-up strings using JavaFX. I'm not sure that it's exactly what you are looking for, but it seems pretty close - it displays random strings for a couple of seconds each, which seems similar to your description, but may be more complicated than what you actually need. – jewelsea Aug 15 '17 at 18:13
-
@jewelsea, thank you, it is I am looking for, I will try a similar solution like that, an additional thing is to have borders, background, close/max/min buttons transparent and having visible only the strings. I tried once (transparent option) to do it in JavaFX, but I was not successfull, maybe some wrong coding from my end – user3422179 Aug 15 '17 at 23:16
-
To have a transparent window without any decorations or background (so just the foreground text is visible), you can see the related question: [how to make transparent scene and stage in javafx?](https://stackoverflow.com/questions/34033119/how-to-make-transparent-scene-and-stage-in-javafx). I would recommend having at least some background color for the text, even if it is a translucent color, so that the text is visible over a range of desktop items, as you never know what color the desktop or windows under the text might be and black on black is not readable. – jewelsea Aug 16 '17 at 21:30
3 Answers
0
System.out.println()
uses the standard output of the Operating System.
To display a message in a GUI, use a graphical API such as the Java standard API for it today : JavaFX.
As a side note, the GUI should work on Windows or Unix based system as a class/jar may be executed on any OS that supports Java : Write once, run anywhere.

davidxxx
- 125,838
- 23
- 214
- 215
0
An example using Swing:
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(400, 100);
frame.setLocationRelativeTo(null);
JLabel label = new JLabel();
frame.add(label, BorderLayout.CENTER);
frame.setVisible(true);
label.setText("TEXT");
Use label.setText()
to update the text displayed.

eliaspr
- 302
- 3
- 15
-
I tried with this example in my machine, but it displays the borders as well as the background color. Is there and other Java library so that it keeps only the strings on the screen ? I tried also to make borders/background transparent, but it didn't work. – user3422179 Aug 15 '17 at 14:22
-
To remove the border, use `frame.setUndecorated(true);` before (!) `frame.setVisible(true);`. Setting the background color can be done using `frame.setBackground(Color.WHITE);`. You can also change the font using `label.setFont(new Font("Comic Sans MS", Font.BOLD, 20));`. – eliaspr Aug 15 '17 at 14:24
0
In order to output information in a separate window from your Java IDE (Eclipse, Intellij, etc...) you need to use a graphical API like others have mentioned. Your best bet would be JavaFX. I will provide some links for useful tutorials and information about JavaFX.
Videos:
- Series of Tutorials on JavaFX: https://www.youtube.com/playlist?list=PLS1QulWo1RIaUGP446_pWLgTZPiFizEMq
- Tutorial on the JavaFX SceneBuilder: https://www.youtube.com/watch?v=Z1W4E2d4Yxo
- JavaFX Tutorial: https://www.youtube.com/watch?v=PDBE-3yaJgo
Sites:
- JavaFX in the Java Docs: http://docs.oracle.com/javase/8/javase-clienttechnologies.htm
- JavaFX Tutorials: http://www.tutorialspoint.com/javafx/

KobiF
- 60
- 1
- 12
-
Don't you think JavaFX is too overpowered for this purpose? I've never used it, so I don't know. – eliaspr Aug 15 '17 at 14:39
-
@Professor901 Yes I think JavaFX is good for larger projects however it is the most up-to-date graphical API. Swing is not longer being updated so it is becoming more obsolete I think. EDIT: JavaFX also seems to be easier to work with because it uses SceneBuilder and fxml files. – KobiF Aug 15 '17 at 14:44