So by default I have no image placed on the window frame and I am looking to add an image to be placed on the corner of the frame when my app runs. I've browsed the forums and saw a bunch of solutions which didn't help me at all. My program runs without errors but the image doesn't show up.. However when the program is ran in linux the main nav-bar (on top) does set the image when I focus on my application, this does not occur in MacOS though.
My Code:
JFrame frame = new JFrame();
JPanel panel = new JPanel();
Image image = null;
URL url = null;
try {
url = new URL("https://www.multivutech.com/images/logo1.png");
image = ImageIO.read(url);
} catch (MalformedURLException ex) {
System.out.println("Malformed URL");
} catch (IOException iox) {
System.out.println("Can not load file");
}
panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
panel.setLayout(new FlowLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
JLabel label = new JLabel("Hello World!", SwingConstants.CENTER);
panel.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Hello World Frame!");
frame.setIconImage(image);
frame.pack();
frame.setVisible(true);
frame.setSize(354, 279);