Eclipse console styling - java

I am looking for a way to print italics out of the Eclipse console. So that some variation of:
System.out.println((Some code)"Hello World");
Outputs:
Hello World
Is this even possible?
Thanks for your help!!

There are a few options available to you with this, but first off, I'll make it clear that this is not a default Java ability. It depends entirely on the Operating System and the output console you are using (Eclipse, Terminal, Command, etc).
JCurses
You can use the JCurses Library to give you additional functions over the default console window. You can find a tutorial here that might help you.
ANSI Escape Sequences
I found a link here that uses ANSI Escape Sequences to modify the text, and ran the code myself to double-check it worked fine. It certainly changed the font, and there are some escape sequences listed here that might help you.
I believe italics should be System.out.println("\030[3mHello World!\030[0m");

Related

Java, not printing Chinese Character in Visual Studios Code, but works in Python

When I do
System.out.println('说');
It just prints "?"
In the bottom right corner it says UTF-8 (so that is good).
I have no idea what I am doing wrong, any help much appreciated.
PS: When I make a python file and print it, it prints it properly. But not in java :(
I tried doing System.setProperty("file.encoding", "UTF-8"); but same result sadly. I tried running code in repl.it, and it works. But not in visual studios.
Note that windows Locale is set to support UTF-8. And I am using Consolas Font, which should support UTF-8.
I also tried uninstalling VS and installing it again - it didn't fix anything.
I am also using terminal for all output.
What is your machine language? Change the system language to Chinese, and modify the system locale to Chinese(you may need to restart the computer), then restart vscode and print out Chinese characters.
Another simple and effective way is to use the Code Runner extension. Install the extension and execute the script with Run Code, the OUTPUT panel will display the result.

Special characters not working on my console (sys out) using eclipse

I was trying to clear the console on java using the eclipse IDE and for some reason, the code isn't working how it is supposed to be working. I think it is something to do with me using eclipse and I am wondering if there is an alternative way to do the following code on eclipse.
System.out.print("\033[H\033[2J");
System.out.flush();
the result I am getting from this code is...
[H[2J
if anyone knows away to get around this I will be happy to know.
Those are ANSI escape codes and they need support from the terminal. The standard terminal doesn't support them, but there are apparently plugins if you need that support (in Eclipse).
The flush() isn't related (or needed) in any way.

Can't print PDF in Java

I'm trying to print some PDFs using Java and I've found a few examples on how to do it. Seems pretty straight forward, but I've been running into problems the whole way.
I first tried PDFBox and it prints, but it doesn't print the document how it should look. A lot of the text gets garbled for some reason. So then I tried using the included Java packages this way and with an example from Oracle but nothing happens. I run the program, I check the print queue in the OS and the job is there, but the printer does nothing. My program exits gracefully with no errors and the print job goes away after a little while but there's still no action from the printer itself.
As an alternative, I've also tried running Adobe Acrobat from within my program but there are no command line arguments to enable duplexing which I need.
If anyone can either help me fix this, suggest another package or command line tool, it would be much appreciated. Thanks!
I found this link helpful ...Your mileage may vary...
The basic idea is to use the java.awt.print package and Apache PDFBox (org.apache.pdfbox.pdmodel.PDDocument)
PDFBox also has command line options to print, encrypt, decrypt, etc.
This is the best solution I found for this matter: ICEPDF.
Printing is 99% loyal to PDF seen on screen, allows silent printng and paper size changing. Only drawback, so far, is that I'm unable to show the print dialog, in same cases I need the user to be able to select printer, page size, number of copies, to name a few, this options are now selected prior by the user in an interface of my app.
Anyway, hope it helps!

JTable won't display Unicode correctly when the application is executed from the command line or a jar file. It works fine in eclipse, though

I'm writing an application that reads a text file containing a list of vocabulary words in both English and Chinese. These are then displayed in a JTable. When I run or debug the app in Eclipse, everything displays fine. I can see and read the characters and the English. However, when I execute the app from the command line or from an executable jar, it's all wrong. The characters show up as either squares or as gibberish.
I also have a text box that when I type Chinese into it, it displays correctly.
My first thought was that it was a font problem. I was using a font installed on my system. Since I can't guarantee that the person using this app will have that font, I moved it to a resource folder and load the font from a file. The font appears as though it's been loaded so I'm convinced it's not a font issue.
I found another question that suggested using -Dfile.encoding=utf-8. I've tried this and it did not work.
Would the brilliant folks at Stack Overflow have any advice on how to make this work?
I'm writing this on a non-chinese version of Windows.
Well then you won't ever be able to get a Java program to produce Chinese command-line output.
Java, like almost all languages, uses the C standard library which has byte-based IO. The Windows command prompt interprets byte-based IO using the locale-specific default code page. That's never a UTF, so Unicode characters outside of the current locale's default code page just won't work.
(In theory you should be able to get it to work by changing your console fonts and using chcp 65001 (UTF-8) together with -Dfile.encoding=UTF-8, but in practice it doesn't work reliably due to bugs in the C runtime. Unicode on the command prompt is a long-standing sore point.)

hebrew appears as question marks in netbeans

I am using netbeans 6.1 on 2 computers.
on one of them the program:
public static void main(String argv[])
{
System.out.println("שלום");
}
prints normally, and the on the other question marks.
what can be the difference between the 2 environments?
edit:
on both computers
Control Panel \ Regional and Language Options \ Advanced
is set to hebrew
edit:
Thank you Michael Burr,
but the value of the encoding is already UTF-8.
Maybe this something with the JVM?
edit:
I have installed Eclipse and the problem occurs there as well.
I also tried reading the hebrew from a file with the same result.
edit:
System.getProperty("file.encoding");
returns "Cp1252"
I tried
System.setProperty("file.encoding","UTF-8")
but the question marks remains.
Thanks,
Ido
Make sure that NetBeans is set up with an encoding that supports Hebrew characters. From the NetBeans Wiki:
To change the language encoding for a project:
Right-click a project node in the Projects windows and choose Properties.
Under Sources, select an encoding value from the Encoding drop-down field.
You can't set the "file.encoding" property with System.setProperty(); it has to be set on the command line when the JVM is started with -Dfile.encoding=UTF-8. The value of this property is read during JVM initialization and cached. By the time your main method is invoked, the value has been cached and changes to the property are ignored.
Is Hebrew installed by default? Could be that a language pack isn't installed?
Control Panel > Regional and Language Options > Languages. Select the 'Install files for complex script and right-to-left languages (including Thai)' option. This will install support for Hebrew. You'll probably need an OS disc.
How exactly are you running the program? Where does it print its output? It could be as simple as netbeans or the console using different fonts, one of which does not include Hebrew characters.
To eliminate encoding problems during compilation, try replacing the Hebrew characters with their unicode escape sequences and see if the result is different.
I think I misunderstood your problem (I thought that the characters were not being displayed in the NetBeans editor properly). The exact steps to solve your problem might depend on the version of the OS you're running on. Win2K, WInXP, and Vista all have slightly different dialogs and wording unfortuantely.
Take a look at this help page for the JVM:
http://java.com/en/download/help/locale.xml
It sounds like you've already configured the system like it should be, but the devil is in the details - there are several different 'locale' settings on a system that might affect this (and for all I know the JVM might throw in one or two on its own).
http://www.siao2.com/2005/02/01/364707.aspx
Usually it's the default encoding on:
Control Panel \ Regional and Language Options \ Advanced
(Select Hebrew on the combo)
You'll have to restart after changing this setting.
What helped me is this (on Win7):
No one answer from above doesn't work.
I spent about an hour, but had figured out, that the problem is located not in the String encoding, but in default encoding, which is used by IDE from the start-up.
So, to get Hebrew, Arabic, Russian etc symbols in Netbeans console output you need to modify netbeans.conf.
Search for the key netbeans_default_options and add -J-Dfile.encoding=UTF-8 into the quotes.

Categories

Resources