I'm trying to change the default java icon that appears in taskbar everytime I run my .jar program. I managed to change it with frame.setIconImage(img); but this makes icon way too small, I want it to be as big as other programs icons and have a high quality. Any way I can do that? Thanks.
As you only supplied a single icon, Windows will then scale that icon to whatever size it needs displaying it in the taskbar (could be 16x16, 32x32 or other sizes, depending on the desktop them and size of the taskbar.
If you want to have a "good looking" icon in the task bar you will need to provide a 32x32 pixel version of your icon.
Once you have that you can call setIconImages(List) instead of setIconImage() to define the icons that the operating system can use:
List<Image> icons = new ArrayList<Image>();
icons.add(getImage("someImage16x16.gif"));
icons.add(getImage("someImage32x32.gif"));
window.setIconImages(icons);
Where getImage() is some method returning the proper image icon. Essentially that would be the same steps you already used to define the current icon.
You can also supply a 64x64 and 24x24 icon using this method (just add more icons to the list).
Try looking at this example. It looks like you need to use frame.setIconImage(Toolkit.getDefaultToolkit().getImage("your_image.gif")); line
Related
I'm doing this project using Swing.
To add a more welcoming feel to the UI, I'm also adding a few Photoshopped images as the background.Here's where the problem begins...
I want the images to automatically resize themselves once the size of the window is increased or decreased, how can I make this happen ?
One way is to override the paintComponent(...) method of a JPanel to paint the image using the drawImage(....) method.
Another option is use a JLabel with an Icon as the background for the frame. Then you can use the Stretch Icon which will automatically scale based on the space available to the label. This is the most flexible solution since the StretchIcon can be used on any component that supports icons.
You can also check out the Background Panel which allows you to display an image. You can display the image at its actual size, scaled or tiled.
In Java documentation about TrayIcon's setImage method (http://docs.oracle.com/javase/7/docs/api/java/awt/TrayIcon.html#setImage(java.awt.Image) says:
If the image represents an animated image, it will be animated automatically.
But I can't get an animated image in the trayicon.
I've tested with PNG and GIF animated, 32x32, 64x64 and 128x128 combinations. But no one works.
Is there any specific format to thses animated tray icon images ?
Check out the Swing tutorial on How to Use the System Tray.
I just changed the gif and it worked fine for me.
The gif I was using was 16x16. I also tried with a 137x116 gif and it worked, although I first had to right click on the "empty area" in the tray and then select the "Auto size" option.
Old question, but in case anyone needs this like me - you have to load the GIF image with new ImageIcon and not ImageIO.read.
trayImage = ImageIO.read(getClass().getClassLoader().getResource("logo.gif")); // DOESN'T WORK
trayImage = new ImageIcon(getClass().getClassLoader().getResource("logo.gif")).getImage(); // WORKS
I'm trying to have an icon be added and displayed to the system tray using Java. However the icon is always either too small, or its cut off in areas.
Its the second one from left in case you couldn't tell.
What am I doing wrong here? How can I get this icon to be displayed fully? What's the standard icon size to be used for system tray?
Edit: I am using AWT SystemTray and TrayIcon
After you've retrieved the actual image resource from disk, you can resize it to the size you need by creating a "fake" one on-the-fly and taking its width.
I found that this was better than using the setImageAutoSize(true) method, as that method does not scale the image smoothly at all.
BufferedImage trayIconImage = ImageIO.read(getClass().getResource("/path/to/icon.png"));
int trayIconWidth = new TrayIcon(trayIconImage).getSize().width;
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
To display the icon at an optimal size, you will need to manually resize it to the correct size. This correct size can differ between operating systems and preferences, so Java provides a method to acquire the task bar icon dimensions, which are 16x16 in the case of your example image.
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Dimension trayIconSize = tray.getTrayIconSize();
// resize icon image to trayIconSize
// create your tray icon off of the resized image
}
According to TrayIcon.setImageAutoSize(boolean).
Sets the auto-size property. Auto-size determines whether the tray image is automatically sized to fit the space allocated for the image on the tray. By default, the auto-size property is set to false.
If auto-size is false, and the image size doesn't match the tray icon space, the image is painted as-is inside that space — if larger than the allocated space, it will be cropped.
I've ended up combining some of these answers to make the code I'm using.
This is producing a good looking icon in my system tray from a png that starts at 100x100.
It's worth noting that on a retina MacBook the icon looks worse scaled down. So I do a check elsewhere to see if it's running on a mac and don't apply this if it is.
public Image imageForTray(SystemTray theTray){
Image trayImage = Toolkit.getDefaultToolkit().getImage("my100x100icon.png");
Dimension trayIconSize = theTray.getTrayIconSize();
trayImage = trayImage.getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH);
return trayImage;
}
How to change the size of JFrame icon?
JFrame f = new JFrame("Test");
Image icon = Toolkit.getDefaultToolkit().getImage("icons/logo.png");
// icon.setPreferredWidth()...
f.setIconImage(icon);
Frame icons are set according to a size decided by the OS.
If you supply icons of various sizes, Windows will use the smaller one for the frame icon, and the larger one as the image to include in the window shown when the user types alt tab to change between apps.
OS X shows no frame icon at all.
See also: Sizes of frame icons used in Swing.
Top Level Containers came from Native OS, from current used theme, then not possible to increase numbers of available pixels,
some dirty hack are possible to wrote in case that you setSystemLookAndFeel, including caption, Font type&size or background, simple don't do that this way,
possible only by implements Custom Look and Feel especially some of Substance's themes can do that
This is the scenario:
I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.
Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).
I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?
Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.
By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link
Cheers
RIchie