gpt4 book ai didi

java - Swing 中使用的框架图标的大小

转载 作者:IT老高 更新时间:2023-10-28 21:10:12 26 4
gpt4 key购买 nike

我们可以使用列表来初始化窗口图标,使用 Window.setIconImages(List<? extends Image>) . 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);
}
}

最佳答案

这台基于 Windows 7 的 PC 的典型 View

注意:@bobbel 报告 Windows 10 使用相同的尺寸。

帧 - 20x20

Icon Size Usage - showing 20x20 frame icon

任务栏 - 任务栏本身的 40x40,悬停应用显示 20x20

Icon Size Usage - Task Bar

Windows+Tab - 20x20

Icon Size Usage - Windows+Tab

Alt+Tab - 右下角 40x40,左上角缩小 20x20。

Icon Size Usage - Alt+Tab

任务管理器 - 20x20

Icon Size Usage - Task Manager

关于java - Swing 中使用的框架图标的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18224184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com