I create an action and set image for this action
Action showErrWarnAct = new Action();
Bundle bundle = FrameworkUtil.getBundle(Activator.class);
URL url = FileLocator.find(bundle, new Path("icons/warning.png"), null);
ImageDescriptor image = ImageDescriptor.createFromURL(url);
showErrWarnAct.setImageDescriptor(image);
I want to change the image of action when hover on it. So I use setHoverImageDescriptor
showErrWarnAct.setHoverImageDescriptor(image2);
But the image does not change when I hover the mouse on it. How can I do it?
I think the very old Eclipse bug fix 53617 changed the behavior of Actions (in tool bars at least) so that the hover image is ignored.
The bug does mention a preference value which can be set in the 'plugin_customization.ini' to use the old behavior.
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)).
When I set the logo for my java plugin, the logo of other windows of eclipse are changed.
I have a class which extends Wizard and implements IObjectActionDelegate. Then, I have override the run function and write the below code in it.
wizard = new StartWizard();
dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
Bundle bundle = Platform.getBundle("Plugin");
URL url = FileLocator.find(bundle, new Path("icon/Logo.png"), null);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
WizardDialog.setDefaultImage(image);
I have read the solution set forth to the similar post on Only changing the logo of special plugin. The problem is that I have extended Wizard and cannot extend WizardDialog instead.
Since you are creating WizardDialog yourself you can actually extend that class if you want.
In a Wizard you can get the current Shell by calling:
Shell shell = getContainer().getShell();
shell.setImage(your image);
It looks like the wizard addPages method would be suitable for this code.
I made a custom Eclipse plugin that uses and displays multiple dialogs, and I want to know if I could set the top left icon image with the one I use in the plugin's icons folder. I want to get that icon and set it instead of the default one that Eclipse uses.
I'm overriding the configureShell() method to change the dialog title, and I also want to change the icon.
#Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), "icons/best.gif"); - this method does not work as it cannot find the file
parent.setImage(icon);
}
I also tried using the getClass().getResource("best.gif") and having the image in the same package, still can't find the location I'm giving(FileNotFoundException), and also, the Image constructor does not accept URL objects.
#Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), getClass().getResource("icons/best.gif"));
parent.setImage(icon);
}
Is there a way to use the icon that I already have in my eclipse plugin?
The main problem is getting the icon from the icons folder of the plugin and making it a Image object.
Thank you.
You can register the icon in your plugins activator class like this:
#Override
protected void initializeImageRegistry(final ImageRegistry reg) {
reg.put(IMAGE_PATH, imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH));
}
The image path is relative to your plugin, e.g. icons/icon.png.
You can access these images via the activator class as well:
final Image image = MyActivatorClass.getDefault().getImageRegistry().get(IMAGE_PATH);
myShell.setImage(image);
(Note that I used the image path as key in the image registry, you do not have to do it like this but it makes everything a little bit less complicated by just using the same static String.)
For an Eclipse plugin you use the FileLocator class to find resources in your plugin.
For an image use something like:
String path = "icons/best.gif";
URL url = FileLocator.find(bundle, new Path(path), null);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
Note: You must arrange for the image to be disposed when no longer needed.
If your activator extends AbstractUIPlugin you can also use the ImageRegistry available from that. The registry will deal with disposing.
Be sure that the icons directory is listed in the build.properties file. Missing this will causes issues when you export your plugin.
I'm using controlsFX for dialogs and I can't figure out how to set the width. A lot of my messages only include the title, masthead and buttons. But the text in the buttons isn't fully display. For example:
Action deleteStuff = new DialogAction("Delete Stuff", ButtonBar.ButtonType.OTHER);
Action deleteMoreStuff = new DialogAction("Delete More Stuff", ButtonBar.ButtonType.OTHER);
Action response = Dialogs.create()
.owner(stage)
.title("Delete")
.masthead("This is a delete dialog")
.actions(deleteStuff,deleteMoreStuff,Dialog.ACTION_CANCEL)
.showConfirm();
And one of the buttons will show: "Delete Mo..."
And yes, I know I should be using the Alert class, but the project is for machines running older versions of Java. Thanks in advance.
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 );