我正在模仿QQ的登录界面。遇到了一个问题,就是怎样在提示工具中加入图标???
高手们帮帮忙。最好有代码。

解决方案 »

  1.   

    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    public class Frame extends JFrame {
     
              public static void main(String[] args) {
                        new Frame().launchFrame();
              }
     
              public void launchFrame() {
                          setSize(300,300);
                          setTitle("窗口示例");                      //获取图片并设为窗口图标,注意,这里的images文件夹必须和Frame.java文件在同一个包中                       java.net.URL imgURL = Frame.class.getResource("/images/yourImage.png");
                           ImageIcon imgIcon = new ImageIcon(imgURL);
                           Image img = imgIcon.getImage();
                           this.setIconImage(img);                      //将窗口显示在屏幕正中
                          this.setLocationRelativeTo(null);
                          setVisible(true);
               }}
    //顺便送楼主一个方法   // 返回图片信息
        private static ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = SysAboutDialog.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            }
            JOptionPane.showMessageDialog(sys_jmu, "找不到 :" + path
                                          + "图片路径!请核实您的配置信息。", "错误",
                                          JOptionPane.ERROR_MESSAGE, null);
            return null;
        }
      

  2.   

    没明白什么叫提示工具?ToolTip 还是 JOptionPane
      

  3.   

    jlabel,joptionpane,tooltip支持html,比如jlabel.setText("<html><img src='file:///F:/Program/Java/Source/YbTools/aa.jpg'></html>");呵呵,44吧,俺用这个做过那个抓天气预报的label很有点意思
      

  4.   

    JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon, options, initialValue)有不同的参数组合,上面就是一个例子,可以自定义Icon的