当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Displaying an alternative text when meet wrong location

问题描述:

I am working for Swing accessibility. I am using ImageIcon. I need to place the alternative textual information when image URL is broken.

网友答案:

For this purpose, all supported Swing Look & Feel implementations include an Icon named "html.missingImage":

Icon missing = UIManager.getIcon("html.missingImage");

A ListCellRenderer using the icon is shown here; a related TableCellRenderer is shown here. Note that each uses setHorizontalTextPosition() and setVerticalTextPosition() to position the label's text relative to the icon.

网友答案:

If I understand well your problem so the answer is : Just surround you code with try and catch

ImageIcon icon = null;
try {
  icon = new ImageIcon(new URL("yourimageUrlHere"));
} catch(Exception e) {
  icon = new ImageIcon("your placeholder path");
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: