fubarable

icon example

Jul 24th, 2020
1,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.image.BufferedImage;
  3. import java.io.IOException;
  4. import java.net.URL;
  5. import javax.imageio.ImageIO;
  6. import javax.swing.*;
  7.  
  8. public class ChessFoo {
  9.     public static void main(String[] args) {
  10.         String bishopPath = "https://upload.wikimedia.org/wikipedia/commons/9/9b/Chess_blt60.png";
  11.         try {
  12.             URL bishopUrl = new URL(bishopPath);
  13.             BufferedImage bishopImg = ImageIO.read(bishopUrl);
  14.             Icon bishopIcon = new ImageIcon(bishopImg);
  15.             JOptionPane.showMessageDialog(null, bishopIcon, "Plain Icon", JOptionPane.PLAIN_MESSAGE);
  16.             JPanel panel = new JPanel(new GridBagLayout());
  17.             panel.setBackground(Color.BLACK);
  18.             panel.setPreferredSize(new Dimension(80, 80));
  19.             panel.add(new JLabel(bishopIcon));
  20.            
  21.             JPanel wrapperPanel = new JPanel();
  22.             wrapperPanel.add(panel);
  23.             JOptionPane.showMessageDialog(null, wrapperPanel, "Black Background", JOptionPane.PLAIN_MESSAGE);
  24.         } catch (IOException e) {
  25.             e.printStackTrace();
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment