Hey guys,
I'm having trouble displaying my icon in the banner of my MainScreen. The Icon is located in the res/ directory. Here's my MainScreen code:
HorizontalFieldManager mngr = new HorizontalFieldManager(USE_ALL_WIDTH);
LabelField label = new LabelField("AACD");
BitmapField pic=new BitmapField(Bitmap.getBitmapResource("res/aacdIconSmall.PNG"),Field.FOCUSABLE);
mngr.add(pic);
mngr.add(label);
this.setBanner(mngr);
BrowserField browserField = new BrowserField();
add(browserField);
The AACD Label shows up above my BrowserField but my pic bitmap never shows up. Any ideas?
Your code is OK.
However I do suspect you did not add the image to your JDE project, so the image is not included in the resulting .cod file during building the project.
No need to use res folder
try Bitmap.getBitmapResource("img/aacdIconSmall.png")
the folder should be like this
res
- img
- aacdIconSmall.png
(i dunno is accdIconSmall.PNG is case-sensitive or not, have not tested yet, just make sure you are using the same upper and lower case)
Related
Here is the simple code for javafx in intellij:
Image image = new Image(url);
ImageView imageView = new ImageView(image);
movieBox.getChildren().add(imageView);
//checking
System.out.println(imageView.getImage().getUrl());
Textfield tx = new Textfield();
tx.setText("hi");
movieBox.getChildren().add(tx);
I copied the project over to intellij on my mac and everything works accept the images won't show. Here are the things I tried:
Checking that the URL is valid by printing out the imageview image url. It prints out a valid URL of an image i can open in my browswer
Adding a random textfield to the movieBox (a flowpane object) to make sure it works. And it does.
There shouldn't be any error in the code because it works in my windows intellij. It seems like a problem with the environment, but I haven't even got a clue how should i approach this problem. Any sort of advice will be nice, thanks!
Try downloading the image and using the path to the image on your disk, if it works then the problem will be with the url, otherwise its with the ImageView. If the problem is with the URL, post the one you are trying to use so the community can test it, and try another URL.
P.S. If you aren't manipulating the image you can just pass the path/url directly top the ImageView constructor.
public ImageView(String url)
Allocates a new ImageView object with image loaded from the specified URL.
The new ImageView(url) has the same effect as new ImageView(new Image(url)).
I am trying to create a button with an image. The API can be found here.
Here is my code:
Button settings = new Button(swpContainer, SWT.PUSH);
settings.setText("Settings");
settings.setImage(new Image(null, "/myProject/icons/settings.png"));
And here is the exception I am getting..
org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: \myProject\icons\settings.png (The system cannot find the path specified))
I am right clicking the image in eclipse and getting the path from the properties.
Any help will be greatly appreciated!
Try this:
Button settings = new Button(swpContainer, SWT.PUSH);
settings.setText("Settings");
Image image = new Image(swpContainer.getShell().getDisplay(),
getClass().getClassLoader().getResourceAsStream("icons/settings.png")); //$NON-NLS-1$
settings.setImage(image);
Presuming myProject is your project name, and icons is a simple folder in the project, then saying new Image(null, "icons/settings.png"); is enough.
I also recommend:
Reading this
Properly managing your resources
If you are writing it for RCP application,try using ImageDescriptor and create image.
Image IMG_EXAMPLE = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"/icons/settings.png").createImage();
I've been trying to get an icon of some APK file, but with no success.
The thing is, I have the APK file path and using that, I want to get its icon (as a Drawable).
Thanx upfront.
Have a look at PackageItemInfo. With that, you can read out the icon for any app installed on the device!
Or even faster: Use
Context.getPackageManager()
to receive a reference on a PackageManager. On that, you can call:
getActivityIcon(Intent i)
The only thing you have still to do is packing the package path in the intent.
Expanding on Matthias' answer, since my original assumed ic_launcher.png:
int icon = 0;
// if you don't know the icon's name:
icon = (new PackageItemInfo()).icon;
// if you do know the icon's name:
icon = R.drawable.ic_launcher; // or whatever your resource id is
Drawable d = getResources().getDrawable( icon );
My requirement is that i need to change all the images and colors at run time. But as far as i know the images needs to be in the drawable folders. So my question is, after i export the apk file will i be able to download the images from a server through the application and set them as the images in the app?
For an example, lets say i have a linear layout with a background image which is in my drawable folder. After installing the app in the device can i download an image from a server and set it as the background of the linear layout?
I hope i have made the question clear. Any help would be greatly appreciated.
Thanks in advance.
try this one (i posted my version for FrameLayout, Imageview should be similar):
String myJpgPath = "/sdcard/picture.jpg";
Bitmap image_b = BitmapFactory.decodeFile(myJpgPath);
final BitmapDrawable image_d = new BitmapDrawable(image_b);
final FrameLayout main = (FrameLayout) findViewById(R.id.main_view);
main.setBackgroundDrawable(image_d);
In my project I have 2 packages.
images - contain images and
notification - contain java files
In notification/main.java I get Image object from image using this code
Image image = Toolkit.getDefaultToolkit().getImage("/images/key-16x16.png");
and I can't get image.
How can I fix this bug.
I'm using Netbeans to develop Java desktop application and I have solved my problem.
Image image = new ImageIcon(this.getClass().getResource("/images/bell-icon16.png")).getImage();
"this" is a class extends JFrame
/ means an absolute path, save Java web-apps where / means relative to context. So, I would suggest to use relative URL, means get rid of that / in front, and then provide the right path.
In case, even then you can't solve it, try to create a file on the same path you are looking for image. This way you will know that where you are looking exactly and where you should look.
You could also try
Image image = new ImageIcon(path).getImage();
Incase the solution above doesn't work, try this (which worked for me):
Image image = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/Images/bell-icon16.png"));
i've also been on this and it turns out that you need to create a package inside of your src folder.
for instace if you create a package called images inside of the src folder, your relative path will be
/images/yourimage.png.
Notice that the slash(/) must be there!
more info here http://forums.macrumors.com/showthread.php?t=533922
it worked for me
Toolkit tk = Toolkit.getDefaultToolkit();
Class<? extends JFrame> j = YOURJFRAME.getClass();
Image image = tk.createImage(j.getResource("/images/bell-icon16.png"));
Try that code, if you have a JFrame that will work.
If you have an Applet, then just use
Toolkit tk = Toolkit.getDefaultToolkit();
Image image = tk.createImage("images/bell-icon16.png");
With applets you never want to use the / in the beginning, but if you have a JFrame, and you are using getResource, you need the / in the beginning of the Path.
SwingResourceManager.getImage(YourClass.class,"key-16x16.png");
The getIcon method will return Icon as similar
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("../resources/MainIcon.png")));