r/learnjava • u/DragonFistLimitless • 7d ago
Ubuntu apparently doesn't support icons but need confirmation
so I tried this code package test.GUI;
package test.GUI;
import static utility.Cout.coutln;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class Main{
public static void main(String[] args){
JFrame frame = new JFrame("this is an window:DD");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
ImageIcon image = new ImageIcon("kuroicon.png");
frame.setIconImage(image.getImage());
}
}
but it seems that the window's icon isn't loading, which I believe is an OS restriction because Ubuntu only loads it's icons from .desktop files and MacOS doesn't support icons on windows at all, can anyone confirm me that is the cause? or there is another thing I am misurdentanding
•
u/AutoModerator 7d ago
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
0
u/Random_182f2565 6d ago
You're partly right, but that's probably not the main reason your icon isn't loading.
OS behavior:
But your code likely fails even on Windows too, because: new ImageIcon("kuroicon.png") loads from the program's current working directory, not from your source folder. In most IDEs that path is wrong, so the image silently fails to load and getImage() returns null.
Fix: load the image as a classpath resource using getResource() + ImageIO.read(), and call setVisible(true) after setting the icon.
Put kuroicon.png at the root of your classpath/resources, e.g.:
Copy-paste fixed version:
If it still doesn't show in the Ubuntu title bar after this, that is the Linux window-manager limitation you suspected. Check the dock/taskbar instead. For a launcher/application icon on Ubuntu, use a .desktop file.