Example usage for javax.swing ImageIcon ImageIcon

List of usage examples for javax.swing ImageIcon ImageIcon

Introduction

In this page you can find the example usage for javax.swing ImageIcon ImageIcon.

Prototype

public ImageIcon(byte[] imageData) 

Source Link

Document

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Usage

From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java

public ThemeBuilderView(SingleFrameApplication app) {
    super(app);/*from w ww. j  a va 2  s. c om*/
    URL iconURL = getClass().getResource("resources/clock2.png");
    getFrame().setIconImage(new ImageIcon(iconURL).getImage());
    initComponents();
    icon = null;
    baseHTML = null;
    baseJS = null;
    baseCSS = null;
    images = new ArrayList<File>(0);
    jLabel9.setVisible(false);
    jLabel10.setVisible(false);
    jLabel11.setVisible(false);
    jTextField5.setVisible(false);
    jTextField9.setVisible(false);
    jTextField10.setVisible(false);
    jButton6.setVisible(false);
    jButton7.setVisible(false);
    jButton3.setVisible(false);
    jScrollPane2.setSize(140, 220);
    jList1.setSize(140, 220);
    jTextField1.setDocument(new DocumentFilter(DocumentFilter.ALPHA_NUMERIC + DocumentFilter.SYMBOLS
            + DocumentFilter.PERIOD + DocumentFilter.SPACE));
    jTextField2.setDocument(new DocumentFilter(DocumentFilter.ALPHA_NUMERIC + DocumentFilter.SYMBOLS));
    jTextField3.setDocument(new DocumentFilter(DocumentFilter.FLOAT));
    jTextField4.setDocument(new DocumentFilter(DocumentFilter.ALPHA_NUMERIC + DocumentFilter.SYMBOLS
            + DocumentFilter.PERIOD + DocumentFilter.SPACE));
    FileDrop drop1 = new FileDrop(jList1, new FileDrop.Listener() {
        public void filesDropped(File[] files) {
            if (files != null && files.length > 0) {
                for (int i = 0; i < files.length; i++) {
                    if (files[i].getName().toLowerCase().endsWith(".png")
                            || files[i].getName().toLowerCase().endsWith(".bmp")
                            || files[i].getName().toLowerCase().endsWith(".jpg")
                            || files[i].getName().toLowerCase().endsWith(".jpeg")
                            || files[i].getName().toLowerCase().endsWith(".gif")) {
                        images.add(files[i]);
                    }
                }
                displayImageList();
            }
        }
    });
    FileDrop drop2 = new FileDrop(jTextField5, new FileDrop.Listener() {
        public void filesDropped(File[] files) {
            if (files != null && files.length > 0) {
                if (files[0].getName().toLowerCase().endsWith(".html")) {
                    baseHTML = files[0];
                    jTextField5.setText(baseHTML.getAbsolutePath());
                }
            }
        }
    });
    FileDrop drop3 = new FileDrop(jTextField9, new FileDrop.Listener() {
        public void filesDropped(File[] files) {
            if (files != null && files.length > 0) {
                if (files[0].getName().toLowerCase().endsWith(".js")) {
                    baseJS = files[0];
                    jTextField9.setText(baseJS.getAbsolutePath());
                }
            }
        }
    });
    FileDrop drop4 = new FileDrop(jTextField10, new FileDrop.Listener() {
        public void filesDropped(File[] files) {
            if (files != null && files.length > 0) {
                if (files[0].getName().toLowerCase().endsWith(".css")) {
                    baseCSS = files[0];
                    jTextField10.setText(baseCSS.getAbsolutePath());
                }
            }
        }
    });
    FileDrop drop5 = new FileDrop(jTextField11, new FileDrop.Listener() {
        public void filesDropped(File[] files) {
            if (files != null && files.length > 0) {
                if (files[0].getName().toLowerCase().endsWith(".png")) {
                    icon = files[0];
                    jTextField11.setText(icon.getAbsolutePath());
                }
            }
        }
    });
    if (ThemeBuilderApp.args != null) {
        if (ThemeBuilderApp.args.length > 0) {
            if (ThemeBuilderApp.args[0].equalsIgnoreCase("-c")) {
                FileDrop drop6 = new FileDrop(jLayeredPane2, new FileDrop.Listener() {
                    public void filesDropped(File[] files) {
                        if (files != null && files.length > 0) {
                            if (FileUtils.getFilename(files[0]).equalsIgnoreCase("control")) {
                                loadControlInfo(files[0]);
                            }
                        }
                    }
                });
            }
        }
    }
}

From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java

private JToolBar getToolbar() {
    if (toolbar == null) {
        toolbar = new JToolBar();
        JButton saveButton = new JButton("Save",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveButton.addActionListener(new ActionListener() {
            @Override//from   ww  w  .ja  va 2 s  . c om
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(false);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton saveasButton = new JButton("Save As...",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveasButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(true);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton openButton = new JButton("Open",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/open_folder.png")));
        openButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                openConfig();
            }
        });
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(openButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveasButton);
    }

    return toolbar;
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

public Actions(final JFrame frame, final ActionPanel ap) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;/* ww  w.j  a v  a  2s . c  om*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ActionSave(name);
                    OtherPanel.updateLists();
                    ButtonPanel.updateLists();
                    ActionPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (actionList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/actions/"
                            + actionList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null,
                            "tes-vous sr de vouloir supprimer cette action?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (actionList.getSelectedValue().equals(ap.getFileName())) {
                            ap.setFileName("");
                        }
                        ap.hide();
                        file.delete();
                        data.remove(actionList.getSelectedIndex());
                        OtherPanel.updateLists();
                        ButtonPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    actionList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(actionList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}

From source file:iqq.app.core.service.impl.ResourceServiceImpl.java

/**
 * ???//from  w w w  .j a  v a 2 s  .c  o  m
 *
 * @param filename
 * @param width
 * @param height
 * @return
 */
@Override
public ImageIcon getUserIcon(String filename, int width, int height) {
    return new ImageIcon(getUserIcon(filename).getImage().getScaledInstance(width, height, 100));
}

From source file:com.uksf.mf.core.utility.loaders.ImageLoad.java

/**
 * Changes colour of all non-transparent pixels for given image to given colour
 * @param image - image to change colours in
 * @param newColour colour to change to//from w ww  .ja v  a  2 s  . co m
 * @return image with changed colours
 */
private static ImageIcon changeImageColour(ImageIcon image, int newColour) {
    LogHandler.logSeverity(INFO, "Converting image: " + image + " colour to: " + newColour);
    BufferedImage bufferedImage = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = bufferedImage.createGraphics();
    image.paintIcon(null, graphics, 0, 0);
    graphics.dispose();
    for (int x = 0; x < bufferedImage.getWidth(); x++) {
        for (int y = 0; y < bufferedImage.getHeight(); y++) {
            int colour = bufferedImage.getRGB(x, y);
            colour = (((colour >> 24) & 0xff) << 24) | (((colour & 0x00ff0000) >> 16) << 16)
                    | (((colour & 0x0000ff00) >> 8) << 8) | (colour & 0x000000ff);
            if (colour != COLOUR_TRANSPARENT.getRGB()) {
                newColour = (((colour >> 24) & 0xff) << 24) | (((newColour & 0x00ff0000) >> 16) << 16)
                        | (((newColour & 0x0000ff00) >> 8) << 8) | (newColour & 0x000000ff);
                bufferedImage.setRGB(x, y, newColour);
            }
        }
    }
    return new ImageIcon(bufferedImage);
}

From source file:net.sf.jabref.gui.PdfPreviewPanel.java

private void renderPDFFile(File file) {

    try (InputStream input = new FileInputStream(file); PDDocument document = PDDocument.load(input)) {
        List<PDPage> pages = document.getDocumentCatalog().getAllPages();

        PDPage page = pages.get(0);//from  ww  w.j a  va2 s  . c  o  m
        BufferedImage image;
        try {
            image = page.convertToImage();
        } catch (Exception e1) {
            // silently ignores all rendering exceptions
            image = null;
        }

        if (image != null) {
            int width = this.getParent().getWidth();
            int height = this.getParent().getHeight();
            BufferedImage resImage = resizeImage(image, width, height, BufferedImage.TYPE_INT_RGB);
            ImageIcon icon = new ImageIcon(resImage);
            picLabel.setText(null);
            picLabel.setIcon(icon);
        } else {
            clearPreview();
        }

    } catch (IOException e) {
        LOGGER.warn("Cannot open file/PDF document", e);
    }
}

From source file:CustomIconDemo.java

public CustomIconDemo() {
    Icon leftButtonIcon = new ArrowIcon(SwingConstants.RIGHT);
    Icon middleButtonIcon = new ImageIcon("images/middle.gif");
    Icon rightButtonIcon = new ArrowIcon(SwingConstants.LEFT);

    b1 = new JButton("Disable middle button", leftButtonIcon);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEFT);
    b1.setMnemonic(KeyEvent.VK_D);
    b1.setActionCommand("disable");

    b2 = new JButton("Middle button", middleButtonIcon);
    b2.setVerticalTextPosition(AbstractButton.BOTTOM);
    b2.setHorizontalTextPosition(AbstractButton.CENTER);
    b2.setMnemonic(KeyEvent.VK_M);

    b3 = new JButton("Enable middle button", rightButtonIcon);
    //Use the default text position of CENTER, RIGHT.
    b3.setMnemonic(KeyEvent.VK_E);
    b3.setActionCommand("enable");
    b3.setEnabled(false);/*ww w. ja v a2 s  . c  o m*/

    //Listen for actions on buttons 1 and 3.
    b1.addActionListener(this);
    b3.addActionListener(this);

    b1.setToolTipText("Click this button to disable the middle button.");
    b2.setToolTipText("This middle button does nothing when you click it.");
    b3.setToolTipText("Click this button to enable the middle button.");

    //Add Components to this container, using the default FlowLayout.
    add(b1);
    add(b2);
    add(b3);
}

From source file:ru.codemine.pos.ui.windows.products.ProductsListWindow.java

public ProductsListWindow() {
    super();//from  w  ww . j  av a 2  s . c  o  m
    setTitle(" ");

    toolButtonPrintStickers = new WebButton(new ImageIcon("images/icons/default/16x16/print-stickers.png"));
    toolButtonPrintStickers.setRolloverDecoratedOnly(true);
    toolButtonPrintStickers.setToolTip(" ?");

    menuItemPrintStickers = new WebMenuItem(" ?",
            new ImageIcon("images/icons/default/16x16/print-stickers.png"));

    operationsMenu.add(menuItemPrintStickers, 4);

    toolBar.addSeparator();
    toolBar.add(toolButtonPrintStickers);

    menuItemProcess.setEnabled(false);
    menuItemUnprocess.setEnabled(false);
    toolButtonProcess.setEnabled(false);
    toolButtonUnprocess.setEnabled(false);
}

From source file:MainClass.java

public MyComboBoxEditor(Map m, IconItem defaultChoice) {
    map = m;/*  ww  w .  j  av  a2s  . c  o  m*/
    panel = new ImagePanel(defaultChoice);
    questionIcon = new ImageIcon("question.gif");
}

From source file:ImageViewer.java

public ImageViewerFrame() {
    setTitle("ImageViewer");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // use a label to display the images
    label = new JLabel();
    add(label);/* w  w  w. ja va  2  s. co  m*/

    // set up the file chooser
    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // set up the menu bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // show file chooser dialog
            int result = chooser.showOpenDialog(null);

            // if file selected, set it as icon of the label
            if (result == JFileChooser.APPROVE_OPTION) {
                String name = chooser.getSelectedFile().getPath();
                label.setIcon(new ImageIcon(name));
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}