I tried to set the application name and icon for the Mac OS X dock in my Java program.
I used the following code:
public static void main(String[] args)
{
Application.getApplication().setDockIconImage(icon); // Dock icon
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Alfabet"); // Program name
new UpdateChecker(); // Check for an update
new Alfabet(); // Start the program
}
The object 'icon' is an java.awt.Image.
The class Alfabet creates the main JFrame of the program. The icon shows up correctly, but the application name doesn't, it still displays the name of the main class of the program. What am I doing wrong? Thank you.
It's not clear where things are going awry, but there's a complete working example here for reference.
Alternatively , try setting the name from the command line:
java -Xdock:name=Alfabet
See also Initial Threads.
Related
I want to stop the blinking cursor while running a program in Java with a Java command in Ubuntu terminal. How can I do it?
Your Java program doesn't exactly have control of the terminal the user ran it from. My advice would be to have your program manage its own window which you can control.
But if you don't feel like doing that then one idea is that there are codes which some terminals listen for. This is very dependent on what terminal you are using but Linux seems to mostly adhere to a spec.
Ubuntu manpages even lists its codes here: http://manpages.ubuntu.com/manpages/focal/man4/console_codes.4.html
Under ECMA-48 Set Graphics Rendition section it says that ESC [ 25 m sets blink off
correction, as mentioned by VGR, this controls whether printed text blinks, not the cursor blink
So search for and try some different codes for your specific terminal and remember to actually run from your terminal as your IDE terminal isn't necessarily the same:
// \u001B is ESC
public static final String ESC = "\u001B";
public static final String HIDE_CURSOR = ESC + "[?25l";
public static void main(String[] args) throws IOException {
System.out.print(HIDE_CURSOR);
System.out.println("Where'd your cursor go??");
}
When I instantiate an object from java.awt, the program causes a new macOS application named "Java", with no windows, to open.
How can I prevent this from happening?
Here is a minimal example:
import java.awt.Rectangle;
public class Main {
public static void main(String[] args) {
Rectangle rect = new Rectangle();
}
}
After compiling and running it in the most canonical way (javac Main.java; java Main), the following icon appears in the Dock: screenshot
I've traced the code, and the offending method is Toolkit.loadLibraries() (JDK 1.8.0_172-b11).
I found the solution based on #MadProgrammer's comment.
The answer is to set AWT to headless mode.
When executing the program:
$ java -Djava.awt.headless=true Main
Or programatically:
System.setProperty("java.awt.headless", "true");
I'm still new to Java and so I'm not understanding where the termination error is coming from. The System.out.println in the main is not being printed out and it says:
< terminated, exit value: 0> C:\Program Files\Java\jre1.8.0_71\bin\javaw.exe (Jan 27, 2016, 1:22:17 PM)
Here is the main of my code.
public class BrainCenter {
public static void main(String[] args) {
System.out.println("Welcome to the Stock Center!");
System.out.println("Realtime Reports within the stock market");
System.out.println("");
Market mk = new Market(6000);
mk.printMarket();
System.out.println("Individual status listed below");
System.out.println("");
Buyers bu = new Buyers();
bu.buildRandomPortfolio(mk);
}
}
The first three lines are not being outputted and I'm not sure why. It appears as the rest of the code loads but then disappear and said to be terminated at the end. I'm using Eclipse IDE.
Any help would be greatly appreciated. Thank you in advance!
Try to use java.exe instead of javaw.exe. The first will wait until the program completes. It will also put all output the program generates directly in console. The last should be used when the program runs with its own GUI or simply in background. It will not wait until the program completes.
See Difference between java.exe and javaw.exe.
you can fix this problem by setting path variable in Environment. In my system I have copied path of bin as "C:\Program Files\Java\jdk1.8.0_25\bin" and saved.
I am using eclipse for long time and this never happened but I have this really simple program . And it doesnt display anything . what can be the reason ?
public class ReportGenerator {
public static void main(String[] args){
System.out.println("STARTING");
}
}
try Window -> Show View -> Console if the console is not visible
If you are doing javac ReportGenerator.java, it is just building a .class file. You need to run java ReportGenerator to see the program working and therefore printing on the terminal in your case.
Too many opened consoles in Eclipse?
Here is the reference: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fconsole%2Fref-open_action.htm
Click the grey X until all of them are closed.
Is there a programatic alternative to setting the dock:name Java Mac OS X property by doing
java -Xdock:name="My App Name" -jar myapp.jar
, or is this the only way to set the dock:name property?
It's been a while, but I believe you need to do the following (this is assuming you're using Swing):
Put your main() method in a separate class from the JFrame.
Before creating the JFrame, set the "com.apple.mrj.application.apple.menu.about.name" system property.
For example:
public class Launcher {
public static void main(String[] args) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Hello World!");
JFrame jframe = new MyJFrame();
jframe.setVisible(true);
}
}
The Apple extensions are documented here:
http://developer.apple.com/mac/library/documentation/Java/Reference/1.5.0/appledoc/api/overview-summary.html
I looked at com.apple.eawt.Application, which gives you access to the icon and menus... but not title, unfortunately.
I am guessing the prescribed approach is to roll out your own App Bundle, as detailed here: http://developer.apple.com/Mac/library/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html