Adding MenuBar Space on Mac - java

On a PC, this issue would not arise, but I have a mac and the java menu bars typically appear on the top left hand area of the screen. For example (from the apple developers website):
The blue highlighted menu is the same name as the main class in a java program. I was wondering how I could name my main method class with a space in between two words rather than an underscore.

I tried...
Using the -Xdock:name="My App Name" on the command line
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Not My Mac App"); within the main method before before and after setting the look and feel
Only -Xdock:name worked.
Tested using Java 8 on 10.9.4, so the settings might be different for earlier version of Java and OS combinations
You may also consider creating a proper Mac .app bundle, which should allow you to set these properties via the plist file...
Take a look at Packaging a Java App for Distribution on a Mac. It is "slightly" out of date, but should lead you in the right direction

Related

Trouble running a Java.jar file with a Swing GUI on Android phone - Major.Minor Version 52.0 & Main Class Name Missing

Hello!
The goal I have is pretty simple: I want to create an executable .jar file which should be able to bring up a form (made using swing) and write the put-in information into a well structurized plain text file. Due to portability/mobility reasons I will have to run this on an Android phone.
Since Android unfortunately doesn't have native Java support and I am unable to code a real Android application myself, I tried to use a Java emulator. Unfortunately, it appears that a working Java Emulator is hard to find to begin with. JBED instantly crashes on my Medion X701. Netmite's Website, which also seems to offer a .jar to .apk converter, appears to be down. JBlend seems to have installed properly, but I do not know how to work with the program now that it presents me nothing but an empty screen with the caption "0 Java ME Application(s)". On the web, I could not find a proper manual. PhoneME's official website was Java.net, which is no longer active. But during my research, I could find an older Version of PhoneME which seems to be running well.
As a test, I created a simple jar file that shows a maximized JFrame. Unfortunately, it isn't able to run my simple executable Jar file on my phone. The main reason for that should be the aforementioned error, which implies that the interpreter there is probably Java version 1.7, since PhoneME's last release was in 2015. There are more error messages referring to an "unknown source", which I believe originate from the first error. I tried to recompile my jar file using Eclipse, by setting the Compiler compliance level to 1.7 and choosing the jre 1.7 before exporting my project. Unfortunately, this didn't change the error messages I got on PhoneME!
As my last attempt, I created a Startup.class file which does the very same thing as my jar file.
import javax.swing.*;
public class Startup {
public static void main(String[] args) {
JFrame fishForm = new JFrame("Questionnaire");
fishForm.setExtendedState(JFrame.MAXIMIZED_BOTH);
fishForm.setVisible(true);
}
}
I compiled it using the command prompt in order to make sure that it is indeed using java 1.7 as the target. This .class file, which ran fine on my computer, leads me into a different error: "Main class name missing.", followed by multiple lines of usage explaination. The command line PhoneME presents doesn't seem to allow me to post command operations myself, as pressing Enter on the virtual keyboard does nothing.
My Questions
Is it even possible to run a Java application on Android which relies on the GUI libraries of Swing, or am I wasting my time?
Is there a different, up-to-date Java emulator for Android which I could use? Or is there a working jar2apk converter somewhere out there?
If not, then there's probably a reason why Java emulators ceased to exist. Is there a much simpler solution for my initial problem which I am missing?
I'll await your ideas eagerly!

How to attach a javaagent to all java applets

I wrote a sample java agent that creates a "hello world" file in a specific place. I want it to run whenever any java applet is run (definitely including ones I didn't write myself.) How do I do that?
My agent works when I run it manually from the command line (as in, running another java file with the agent attached to it.) On the automatic front, I tried going into the java configuration panel -> Java -> View -> JRE Configuration Settings -> setting the optional arguments to attach my agent, but that doesn't seem to do the trick. I browse with FF to someplace that makes me run a java applet but no file is created.
I'm guessing I'm missing something basic here, because when I try to google this people all around various forums seem to answer it as if it's the most trivial thing: "just use -javaagent, read more about it in this (link)."
If it helps at all, this is the optional parameter I add in the configuration panel (which works when I use it manually):
-javaagent:C:\Users\admin\workspace\poc\bin\poc\myagent.jar
Update: I found out I can set an environment variable (JAVA_TOOL_OPTIONS) to -javaagent:(agentpath). Once again it works flawlessly with local java applications, but now when I browse over to a webpage with an applet, firefox auto-closes itself. IE declares the webpage broken. Chrome doesn't even display the applet. The agent itself at this point does nothing - it just has an empty premain method. Anyone?
Setting the environment variable JAVA_TOOLS_OPTIONS=-javagent:(path) is right.
My error was that I misconstructed the .jar file. Once I fixed that (simply used the jar.exe tool to make my .jar) it worked properly - locally and on all applets via firefox. Until then, that was what caused firefox to either hang or crash when encountering an applet.

Java Mac OS X Application Name Correction

I have launched my application in Mac OS X. Next to the Apple icon in the top left corner of the screen appears the name of my application. This name appears as the package path of my main class (i.e. pack.age.Uno instead of Uno).
Does anyone know how to fix this annoying thing?
Just add this parameter when launching the program:
-Xdock:name=MyApp
I've been annoyed by this too. There is no way I know of to override in code reliably. I'll get it working with if (System.getProperty("os.name").contains("Mac")) System.setProperty("com.apple.mrj.application.apple.menu.about.name","My Java App"); but com back later and it wil be back to the "com.me.myapp". On release you can use Jar Bundler to make an app bundle and then the problem goes away.

Setting Java Swing application name on Mac

I'm writing a Java Swing application for the Mac using Java 1.6. I've read a number of tutorials that step you through how to better integrate your Java application with OS X, but there's one thing I haven't been able to get working. I can't get the application name (the first, bolded menu item in the Mac menu bar) to display. By default, the fully-qualified class name of the main class is shown and I can't get it to change.
This site says that you have to set the following property:
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");
But that doesn't work (I'm running 10.6, so maybe the property name changed?).
When I create a new Java project in XCode (I normally use Eclipse), the name somehow magically gets set! (it starts you out with a runnable, boiler-plate application) I've looked all around the XCode project for how this is done, but I can't figure it out!
My guess is that it only sets the application name if you wrap your Java application up in a Mac *.app package, but was wondering if anyone knew the answer. Thanks.
EDIT: Interestingly, it sets the application name if I package my application in a runnable JAR file, but not if I run it from Eclipse.
You should do the following during app initialization, before GUI is built:
// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");
// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");
// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UPDATE.
Above code works in Java 1.5, this code may not work in 1.6
For new java see documentation:
Either use -Xdock:name command-line property: -Xdock:name=YourAppName
Or set CFBundleName in information property list file (plist)
On Mac 10.7.5, programatically setting the property will work with with Java 1.6 but not with Java 1.7.

<ProjectName.ProjectUI sucks as a name for my Netbeans java OS X app

What property in Netbeans to I need to change to set the name of my java swing app in the OS X menubar and dock? I found info.plist, but changing #PROJECTNAMEASIDENTIFIEER# in multiple keys here had no effect.
Thanks,
hating netbeans.
The answer depends on how you run your application. If you run it from the command line, use '-Xdock:name=appname' in the JVM arguments. See the section "More tinkering with the menu bar" in the article linked to by Dan Dyer.
If you are making a bundled, double-clickable application, however, you just need to set the standard CFBundle-related keys in your application's Info.plist (see the documentation on Info.plist keys for more details).
Check:
nbproject/project.properties
nbproject/project.xml
in project.xml look for the name element...
But... Why not just select the main project and right click and do rename?
This is not NetBeans-specific, but this article has some useful tips about tweaking your Swing apps so that they fit in on OS X.

Categories