Javaの画像アイコンと、Swingアプリケーションのドロップダウンメニューから選択できる画像アイコンを制限する方法について少し質問があります。
私はマルチプラットフォームのJavaプログラムを開発しており、使用中のオペレーティングシステムに応じて、ドロップダウンメニューから選択できるアイコンを制限する方法を見つけることができません。
たとえば。たとえばWindowsベースのPCでLinuxアイコンを選択すると、ユーザーはこれがLinuxではないがWindowsが再度選択するという小さなメッセージを受け取るはずです。
これまでの私のコードは、エラーなどなしでアイコンをロードするという点で機能します
private String img[] = {
"default.png",
"window.png",
"linix.png",
"macos.png",
"solaris.png"};
private ImgIcon[] icon = {
new ImageIcon(getClass().getResource(img[0])),
new ImageIcon(getClass().getResource(img[1])),
new ImageIcon(getClass().getResource(img[2])),
new ImageIcon(getClass().getResource(img[3])),
new ImageIcon(getClass().getResource(img[4]))};
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt)
{
if (IsWin()) {
jTextArea1.setText("Detected OS : " + os);
}
else if (IsMac()) {
jTextArea1.setText("Detected OS : " + os);
}
else if (IsLin()) {
jTextArea1.setText("Detected OS : " + os);
}
else if(IsSol()) {
jTextArea1.setText("\Detected OS : " + os);
}
}
これまでのところ、表示されるアイコンを選択すると機能し、JTextAreaにオペレーティングシステムが何であるかを示す小さなメッセージが表示されます...ユーザーが間違ったオペレーティングシステムアイコンを選択した場合は、何らかの方法でユーザーに警告する必要があります。別のオペレーティングシステムで!
任意の提案をいただければ幸いです!