Sizes of frame icons used in Swing
Solution 1
Typical views for this Windows 7 based PC
Note: @bobbel reports the same sizes are used for Windows 10.
Frame - 20x20
Task Bar - 40x40 in task bar itself, hover app shows 20x20
Windows+Tab - 20x20
Alt+Tab - 40x40 in lower right, shrunken 20x20 in upper left.
Task Manager - 20x20
Solution 2
@mKorbel Huh.. did not realize there would be a difference there. Well, user/OS preferences rules over programmer expectation! ;)
answer is only about Win8(ent, 64b ....)/WinXP(not mentioned, but setting are quite similair)
there are another options please see Bug or feature: Swing default gui font incorrect for Win6+ by @kleopatra, etc
is possible to set 64x64 icon on desktop in win8
e.g. my setting (not advanced graphics personalizations, despite the fact that I'm Win2008/12 admin,
blablabla-
"leaving surealism with reversed color scheme, now only with Black & Orange Colors"-end blablabla
)
- generating
- standard setting (only unmarked Use small taskbar buttons)
- your window on my screen
Solution 3
It seems there are no Frame or Dock icons when run in Mac OS X 10.9 (Mavericks):
Also, no icon in Activity Monitor:
Solution 4
Ubuntu 12.04 LTS
The taskbar icon size can be changed between 32 and 64, but all the time uses the 32x32 icon. I have also recompiled the program, but keeps using the same icon.
Taskbar and window (there is not icon at windows).
Alt + Tab
no icon at task manager
Solution 5
This is my result on windows 10, it is depending on the Screen scaling:
At 100%: Frame - 16x16 Taskbar - 32x32
At 125% Frame - 20x20 Taskbar - 40x40
At 150% Frame - 24x24 Taskbar - 48x48
At 175% Frame - 28x28 Taskbar - 56x56
At 200% Frame - 32x32 Taskbar - 64x64
Andrew Thompson
Java desktop app. enthusiast (for the x-platform, rich client experience). No strong opinions on technologies, platforms etc. beyond that. Author of the SSCCE and wrote the initial draft of the MCVE at SO. Also seen at DrewTubeish. Some of the tools formerly available at my pscode.org domain can be downloaded from my Google Share Drive. At StackExchange: Completed the Java Web Start, JNLP, Applet & Java Sound tag information pages. Top user in same tags. Asked the How to create screenshots? FAQ & wrote the Why CS teachers should stop teaching Java applets blog post. One of the most prolific editors of questions & answers. Most active on StackOverflow but also seen at other places around StackExchange such as Space Exploration, Sci-Fi & Fantasy & Movies & TV.
Updated on June 14, 2022Comments
-
Andrew Thompson almost 2 years
We can use a list to initialise the window icons using
Window.setIconImages(List<? extends Image>)
. What are the different sizes of icons typically used for in aJFrame
?Code
This code turns 64 different sized images (from 16x16, incrementing by 2) into icons for the list.
import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; public class FrameIconList { public static BufferedImage getImage(int size, Color color) { BufferedImage i = new BufferedImage( size, size, BufferedImage.TYPE_INT_RGB); Graphics2D g = i.createGraphics(); g.setColor(color); g.fillRect(0, 0, size, size); g.setColor(Color.BLACK); int off = (size>17 ? 3 : 1); if (off>1) g.drawRect(0, 0, size-1, size-1); g.drawString("" + size, off, size-off); g.dispose(); return i; } public static void main(String[] args) { final Color[] colors = { Color.GREEN, Color.RED, Color.YELLOW, Color.WHITE, Color.CYAN, Color.MAGENTA, Color.PINK, Color.ORANGE }; int s = 64; final int[] sizes = new int[s]; for (int ii=0; ii<sizes.length; ii++) { sizes[ii] = 16+(ii*2); } Runnable r = new Runnable() { @Override public void run() { // the GUI as seen by the user (without frame) JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new EmptyBorder(2, 3, 2, 3)); gui.setBackground(Color.WHITE); ArrayList<BufferedImage> images = new ArrayList<BufferedImage>(); Vector<ImageIcon> icons = new Vector<ImageIcon>(); for (int ii=0; ii< sizes.length; ii++) { BufferedImage bi = getImage( sizes[ii], colors[ii%colors.length]); images.add(bi); ImageIcon imi = new ImageIcon(bi); icons.add(imi); } JList list = new JList(icons); list.setVisibleRowCount(6); gui.add(new JScrollPane(list)); JFrame f = new JFrame("Icon size usage"); f.setIconImages(images); f.add(gui); // Ensures JVM closes after frame(s) closed and // all non-daemon threads are finished f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // See http://stackoverflow.com/a/7143398/418556 for demo. f.setLocationByPlatform(true); // ensures the frame is the minimum size it needs to be // in order display the components within it f.pack(); // should be done last, to avoid flickering, moving, // resizing artifacts. f.setVisible(true); } }; // Swing GUIs should be created and updated on the EDT // http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html SwingUtilities.invokeLater(r); } }