Java Swing中使用的框架图标的大小
我们可以使用列表来初始化窗口图标。在Java Swing中使用的框架图标的大小,java,swing,icons,jframe,imageicon,Java,Swing,Icons,Jframe,Imageicon,我们可以使用列表来初始化窗口图标。在JFrame中通常使用的图标大小有哪些 代码 此代码将64个不同大小的图像(从16x16,递增2)转换为列表的图标 import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; pub
JFrame
中通常使用的图标大小有哪些
代码
此代码将64个不同大小的图像(从16x16,递增2)转换为列表的图标
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);
}
}
import java.awt.*;
导入java.awt.image.buffereImage;
导入java.util.ArrayList;
导入java.util.Vector;
导入javax.swing.*;
导入javax.swing.border.EmptyBorder;
公共类框架列表{
公共静态缓冲区图像getImage(整数大小、颜色){
BuffereImage i=新的BuffereImage(
大小、大小、缓冲区图像。类型为_INT_RGB);
Graphics2D g=i.createGraphics();
g、 设置颜色(颜色);
g、 fillRect(0,0,size,size);
g、 设置颜色(颜色为黑色);
int off=(大小>17?3:1);
如果(off>1)g.drawRect(0,0,size-1,size-1);
g、 抽绳(“+尺寸,关闭,关闭尺寸);
g、 处置();
返回i;
}
公共静态void main(字符串[]args){
最终颜色[]颜色={
颜色,绿色,
颜色,红色,
颜色,黄色,
颜色,白色,
颜色,青色,
颜色,洋红,
颜色,粉红色,
橙色
};
int s=64;
最终整数[]大小=新整数[s];
对于(int ii=0;ii此基于Windows 7的PC的典型视图
注:@bobbel报告Windows 10使用相同的大小
帧-20x20
任务栏-40x40在任务栏中,悬停应用程序显示20x20
Windows+选项卡-20x20
Alt+Tab-右下角为40x40,左上角为缩小的20x20。
任务管理器-20x20
@mKorbel嗯..没有意识到会有不同。
好吧,用户/操作系统的偏好规则超过了程序员的期望!;)
- 答案只是关于Win8(ent,64b…)/WinXP(未提及,但设置非常相似)
- 还有另一个选项,请参见@kleopatra等
- 可以在win8的桌面上设置64x64图标
- e、 g.我的设置(不是高级图形个性化,尽管我是Win2008/12管理员,
blablabla-
“使用反向配色方案保留surealism,现在只使用黑色和橙色”-结束blablabla
)
- 产生
- 标准设置(仅使用未标记的小任务栏按钮)
- 你的窗口在我的屏幕上
在Mac OS X 10.9(Mavericks)中运行时,似乎没有框架或停靠图标:
此外,活动监视器中没有图标:
Ubuntu 12.04 LTS
任务栏图标大小可以在32和64之间更改,但始终使用32x32图标。我也重新编译了程序,但一直使用相同的图标
任务栏和窗口(windows上没有图标)
Alt+Tab
在任务管理器中没有图标我在Win10上发现了一件有趣的事情(对于Win7和Win8也可能是这样,但我还没有尝试过)
默认情况下,Win10将使用20x20(小)和40x40(大)的图像大小
那么,如果您将图像大小设置为22?它将使用图像大小30x30(小)和40x40(大)
生成一个完整的表显示了有趣的行为(测试开始大小之间的测试会产生以前的大小;因此4也会产生20x20和40x40):
如果从2开始,它将使用20x20和40x40
如果从22开始,它将使用30x30和40x40
如果从32开始,它将同时用于40x40
如果从42开始,它将同时用于60x60
如果从62开始,它将使用78x78和80x80
如果从80开始,它将同时用于80x80
如果从82开始,它将使用98x98和120x120
如果从100开始,它将使用100x100和120x120
如果从102开始,它将使用118x118和120x120
如果从120开始,它将同时用于120x120
如果从122开始,它将使用138x138和158x158
……好了,这就够了
我真的不明白背后的模式,但我发现它非常有趣
最终取决于您提供的大小。每个操作系统都有自己的逻辑来显示特定的图标。如果您不提供每个操作系统的确切图像大小,它将被放大或缩小。这是我在windows 10上的结果,它取决于屏幕缩放:
100%时:
机架-16x16
任务栏-32x32
125%
帧-20x20
任务栏-40x40
150%
帧-24x24
任务栏-48x48
175%
机架-28x28
任务栏-56x56
200%
机架-32x32
Taskbar-64x64刚刚测试过:在Win10中大小也一样。在Mac上部署Java应用程序并不像在Windows上那么容易让它感觉像是本地的。最初的步骤是将Java应用程序包装在一个.app目录中,其中包含一个Info.plist描述符文件,该文件反过来指向一个可用于该应用程序的图标。请参阅。@EthanB,我找到的唯一解决方案是java-Xdock:name=“我的应用程序”-Xdock:icon=“/path/to/myicon.icns”
这个问题已经有6.5年了,已经有很多答案,其中一个已经被接受。是的,接受的答案对于Windows 10是不正确的。