How to launch draw9patch and is it absolutely necessary to rescale pictures? - java

I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk. I did that but i still cannot launch the file. Is this tool absolutely necessary for your pictures to scale on different screens? I know that eclipse has these drawable folders that scale your pictures to different dpis or is that not what they do?
Console output: http://imgur.com/YdGLHXr
File skd/tools :http://imgur.com/vOU647L

To answer the first question for a Mac OS or Linux user, simply type sh draw9patch to launch the editor. CommonsWare already answered the second question.

I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk
Please use the draw9patch batch file or shell script found in the tools/ directory of your SDK installation.
I did that but i still cannot launch the file
First, that is because you did not type it in correctly, as you did not include the .jar extension.
Second, that JAR file is not in that directory. You can tell that by looking at the directory contents.
Instructions for running draw9patch can be found in the Android documentation.
Is this tool absolutely necessary for your pictures to scale on different screens?
Quoting the documentation:
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background.
Scaling for different screens is not really the role of a nine-patch PNG file. Scaling for different content is. A nine-patch is used as the background for widgets like Button, EditText, and the like.

Related

How to add "About" tab on Mac

On a Mac, there is a button on the screen menu bar that is the name of an application. For example, for terminal, there is a button at the top of the screen labeled Terminal. When you click it, there is a options that says About Terminal. When this is clicked, it shows information about the application. Here is a picture:
How can I add this to my application in Java? When I do this now, this is what shows up:
As you can see, it shows the Java version etc. Is there a way to change this into a more professional format?
If your Window extends JFrame, just use the setIconImage or setIconImages method to set your icon.
From the corresponding JavaDoc:
Sets the image to be displayed as the icon for this window.
The other information is read from the executable metadata. If you run your app using Java directly, you can't change it. For my applications, I generate an executable file using Install4J, where the installer adds the metadata to the generated executable.
Thanks, I've solved the problem. It was a simple mistake, when I packaged it together using a packager it worked fine. Thanks for all your help!

Java 9+ Equivalent to Manifest Defined Splash Screen

I recently upgraded my application from Java 8 up to Java 12. I used to distribute as a runnable jar file, but am now distributing a runnable image. In the past, I defined a splash screen in the manifest which would display while the app loads (and well before a single line of my code ran). Is there any equivalent functionality I can use now that I have switched from running from a jar file to running from an image?
Check the documentation of java.awt.SplashScreen:
If the Java implementation provides the command-line interface and you run your application by using the command line or a shortcut, use the Java application launcher option to show a splash screen. The Oracle reference implementation allows you to specify the splash screen image location with the -splash: option.
For example:
java -splash:filename.gif Test
or of the java command:
-splash:imagepath
Shows the splash screen with the image specified by imagepath. HiDPI scaled images are automatically supported and used if available. The unscaled image file name, such as image.ext, should always be passed as the argument to the -splash option. The most appropriate scaled image provided is picked up automatically.
For example, to show the splash.gif file from the images directory when starting your application, use the following option:
-splash:images/splash.gif

Libgdx stuck generating an app

When I click on the downloaded libgdx file I select run with Java then the libgdx window pops up I check android (and tried to check desktop too) and leave the names default and some times I tried to change them and for extensions I leave it as default the only one checked is box 2D.
Its says in the little console below that it's generating an app in my desired path then its just stuck there for hours.
(I checked task manager and its not using almost any resources other than 60 mbs of ram)
This problem could possibly happen if the application cannot write into the destination folder you choose. So avoid making the destination folder inside the system32 folder or such.
Run the jar file from the command prompt to see the exception it generates which should explain the problem:
Hold down the Windows button and tap the 'r' key.
In the dialog type 'cmd' then enter.
Copy this text using ctrl-c, include all quotes. Adjust the file names to point to your Java VM runtime and your downloaded
gdx-setup.jar file: "C:\Program
Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\java.exe" -jar "C:\Users\keith\Downloads\gdx-setup.jar"
Paste the text into the command prompt by pressing ctrl-insert (the zero key on the numpad). Alternatively, tap the top left icon,
then edit, then paste.
See what the specific exception is in the cmd console when the gdx setup program runs.

How do I build in images to my app

I have a java application. And It loads images from a directory
"C:\\Users\\elliotbewey\\Desktop\\IMGS\\BOB.png"
And it loads fine the image displays. Now If I was to compile it into a runnable jar and send it to my friend. it would not work. What would I need to do get a installer? And get system information? Help!
//note I do understand that its going to my friends computer so \\users\\elliotbewey would not work because its his computer thats what I need help with
You need to package your images inside your jar, then reference them as resources. Doing a google search for "java package images inside jar as resource" will give you a ton of results and tutorials.
This approach will work from an IDE on your computer or from a packaged jar on your friend's computer. Using an installer is definitely overkill for this goal.
Locate your images inside jar file (for example res/image.png).
Then simply call this to get BufferedImage:
BufferedImage image = ImageIO.read(YourClassName.getClass().getResourceAsStream("/res/image.png"));

How to change default jar icon

First I have read all questions about this subject, so this is not a repeated question.
What I want to ask about, how an application written in Java (such as eclipse) uses an icon instead of the default jar icons.
I don't care about compatibility, I always can make 2 different versions of my program to Windows and Linux.
How to make it in Linux and Windows.
Thanks very much.
In the case of programs like eclipse, which are written in java and have a specific icon in Windows (or Linux or Mac for that matter), they actually have an OS specific executable file, e.g. eclipse.exe for windows, that initialises the java program.
It is this executable that contains the application icon, not the Java program. If you want to do the same, you'll need to create the executable 'front door', as it were, and give it an icon.
If it's just for your own personal aesthetics, just create a short cut to the jar file and change the icon of the shortcut.
To set an image for MAC, you can use com.apple.eawt.Application. try this:
Image img = new ImageIcon("abc.png").getImage(); // your desired image
Application app = Application.getApplication();
app.setDockIconImage(img);
However, this will not build on Windows or Linux by default. If you'd like it to, (Maven) add the following dependency to your POM:
<dependency>
<groupId>com.yuvimasory</groupId>
<artifactId>orange-extensions</artifactId>
<version>1.3.0</version>
</dependency>
Or, if you don't use Maven, you can download the JAR from http://central.maven.org/maven2/com/yuvimasory/orange-extensions/1.3.0/orange-extensions-1.3.0.jar
If the application is launched using Java Web Start, an application icon can be specified for use in desktop shortcuts and menu items.
Note that this icon is not attached directly to the Jar, but since the end user never sees or has to deal with a Jar, that should not be a problem.
I use NetBeans, so if you aren't using that, I don't quite know. But, when you select the window, there is an option in the properties window for an icon file. When you build the .jar, that icon should be built in with the program.
If you're talking about the actual application icon in, say, Windows, you can't change it (programmatically). That's determined by the OS. Although you can change it in your OS in Folder Options.
You can, however, set the window (read: JFrame) icon image using setIconImage().

Categories