简体   繁体   English

为所有子框架设置默认的Java桌面应用程序图标?

[英]Setting the default java desktop app icon for all sub-frames?

I've managed to replace the java coffee cup in the corner with my own icon, however my application has about 13 frames, and when I manually call the icon like I did on my mainframe it says cannot find symbol getframe(). 我已经设法用自己的图标替换了角落里的Java咖啡杯,但是我的应用程序大约有13帧,当我像在大型机上那样手动调用图标时,它说找不到符号getframe()。

Any idea how to set the default icon to the icon the main frame has? 知道如何将默认图标设置为主机的图标吗? I used this code to apply my icon to the main frame: 我使用以下代码将图标应用于主框架:

URL url = ClassLoader.getSystemResource("calculatormedii/resources/CMed1.png");
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(url);
        getFrame().setIconImage(img);

"sub frames" should be a JDialog and not a JFrame. “子框架”应该是JDialog,而不是JFrame。 The dialog will inherit the icon automatically as long as you specify the frame as the parent of the dialog in the constructor. 只要您在构造函数中将框架指定为对话框的父级,对话框就会自动继承图标。

  1. as I know not possible to easilly change Java Cup Icon for containers built from Java Desktop Aplication 据我所知,不可能轻易更改从Java Desktop Aplication构建的容器的Java Cup Icon

  2. Java Desktop Aplication is old Framework based on Swing, but lots of methods are protected and not accesible from outside Java Desktop Aplication是基于Swing的旧框架,但是许多方法受到保护,并且无法从外部访问

  3. since (at first sight) looks like as very confortable just drad & drop pre_defined jComponents from palette, but change part of basic methods not easy job, 因为(乍一看)看起来很舒服,只是从调色板中删除了预定义的jComponents,但是更改了一些基本方法并不容易,

  4. Java Desktop Aplication is old Framework and is depreciated a few years Java Desktop Aplication是旧的Framework,并且已贬值了几年

  5. use standard Swing JComponent, then you can't find any limits 使用标准的Swing JComponent,那么您将找不到任何限制

You can try something like this: 您可以尝试如下操作:

URL url = ClassLoader.getSystemResource("calculatormedii/resources/CMed1.png");
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(url);

        Frame[] frames = JFrame.getFrames();
        for (int i = 0; i < frames.length; i++) {
            frames[i].setIconImage(img);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM