gpt4 book ai didi

java - 自定义 JOptionPane 图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:00 26 4
gpt4 key购买 nike

Java 的 "How to Make Dialogs"教程显示此代码:

//custom title, custom icon
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.",
"Inane custom dialog", JOptionPane.INFORMATION_MESSAGE, icon);

这将创建以下对话框:

Java's Example Dialog

当图标将更改为 icon 参数时,为什么需要 JOptionPane.INFORMATION_MESSAGE

最佳答案

该标志还指示在窗口装饰上使用哪种消息样式,请参阅 http://nadeausoftware.com/node/91#Usinglookandfeelspecificwindowdecorations

来自 JOptionPane 类源代码:

private static int styleFromMessageType(int messageType) {
switch (messageType) {
case ERROR_MESSAGE:
return JRootPane.ERROR_DIALOG;
case QUESTION_MESSAGE:
return JRootPane.QUESTION_DIALOG;
case WARNING_MESSAGE:
return JRootPane.WARNING_DIALOG;
case INFORMATION_MESSAGE:
return JRootPane.INFORMATION_DIALOG;
case PLAIN_MESSAGE:
default:
return JRootPane.PLAIN_DIALOG;
}
}

并且在 showMessageDialog 调用的方法 showOptionDialog 中...

int style = styleFromMessageType(messageType);
JDialog dialog = pane.createDialog(parentComponent, title, style);

关于java - 自定义 JOptionPane 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18499032/

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