Example usage for javax.swing ImageIcon setImage

List of usage examples for javax.swing ImageIcon setImage

Introduction

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

Prototype

public void setImage(Image image) 

Source Link

Document

Sets the image displayed by this icon.

Usage

From source file:Main.java

public static JFrame getImageJFrame(BufferedImage image) {
    ImageIcon icon = new ImageIcon();
    icon.setImage(image);
    JFrame frame = new JFrame();
    frame.add(new JLabel(icon));
    frame.pack();/*from   w w  w.  j  ava  2  s  . c om*/
    return frame;
}

From source file:Main.java

/**
 * Resizes the icons of all the abstract buttons which are contained in
 * a container./*from w  w  w .j ava 2  s .  c o m*/
 * 
 * @param container a container containing abstract buttons
 * @param size the size which should be used for the icons
 */
public static void scaleAllAbstractButtonIconsOf(Container container, int size) {
    for (final Component c : container.getComponents()) {
        if (c instanceof AbstractButton) {
            final ImageIcon i = (ImageIcon) ((AbstractButton) c).getIcon();
            if (i != null) {
                i.setImage(i.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
            }
        }
    }
}

From source file:gdt.jgui.console.JItemPanel.java

public void resetIcon() {
    if (icon$ != null) {
        byte[] ba = Base64.decodeBase64(icon$);
        ImageIcon icon = new ImageIcon(ba);
        Image image = icon.getImage().getScaledInstance(24, 24, 0);
        icon.setImage(image);
        title.setIcon(icon);/* w ww.j a  v  a  2  s .  com*/
        title.repaint();
        title.revalidate();
    }
}

From source file:gdt.jgui.console.JItemPanel.java

/**
 * Create the item panel.//from  w w w.  ja  va 2s.c  o  m
 * @param console the main console.
 * @param locator$ the item's locator.
 * @return the item panel.
 */
public JItemPanel instantiate(JMainConsole console, String locator$) {
    try {
        this.console = console;
        this.locator$ = locator$;
        this.removeAll();
        Properties locator = Locator.toProperties(locator$);
        if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKABLE))) {
            checkbox = new JCheckBox();
            add(checkbox);
            if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKED)))
                if (checkbox != null)
                    checkbox.setSelected(true);
        }
        title = new JLabel(title$, JLabel.LEFT);
        //title.setIcon(null);
        title$ = locator.getProperty(Locator.LOCATOR_TITLE);
        if (title$ != null) {
            title.setText(title$);
            title.setOpaque(true);
            title.addMouseListener(new MousePopupListener());
            title.setAlignmentX(Component.LEFT_ALIGNMENT);
            add(title, BorderLayout.WEST);
            icon$ = locator.getProperty(Locator.LOCATOR_ICON);

            if (icon$ != null) {
                byte[] ba = Base64.decodeBase64(icon$);
                ImageIcon icon = new ImageIcon(ba);
                Image image = icon.getImage().getScaledInstance(24, 24, 0);
                icon.setImage(image);
                title.setIcon(icon);
            }
        } else
            LOGGER.info("title is null");
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return this;
}

From source file:gdt.jgui.console.JItemPanel.java

/**
 * The constructor./*from w  ww .j  a  v  a 2s. co  m*/
 * @param console the main console.
 * @param locator$ the item's locator.
 */
public JItemPanel(JMainConsole console, String locator$) {
    this.console = console;
    this.locator$ = locator$;
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    setAlignmentX(Component.LEFT_ALIGNMENT);
    try {
        this.console = console;
        this.locator$ = locator$;
        Properties locator = Locator.toProperties(locator$);
        if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKABLE))) {
            checkbox = new JCheckBox();
            add(checkbox);
            if (Locator.LOCATOR_TRUE.equals(locator.getProperty(Locator.LOCATOR_CHECKED)))
                if (checkbox != null)
                    checkbox.setSelected(true);
        }
        title$ = locator.getProperty(Locator.LOCATOR_TITLE);
        if (title$ != null) {
            title = new JLabel(title$, JLabel.LEFT);
            title.setText(title$);
            title.setOpaque(true);
            title.addMouseListener(new MousePopupListener());
            title.setAlignmentX(Component.LEFT_ALIGNMENT);
            add(title, BorderLayout.WEST);
            icon$ = locator.getProperty(Locator.LOCATOR_ICON);
            if (icon$ != null) {
                byte[] ba = Base64.decodeBase64(icon$);
                ImageIcon icon = new ImageIcon(ba);
                Image image = icon.getImage().getScaledInstance(24, 24, 0);
                icon.setImage(image);
                title.setIcon(icon);
            }
        } else
            LOGGER.info("title is null");

    } catch (Exception e) {
        LOGGER.severe(e.toString());

    }
}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * Create the context./*from  www  .  jav a2  s  .  c  o  m*/
 * @param console the main console.
 * @param locator$ the locator string.
 * @return the procedure context.
 */
@Override
public JContext instantiate(JMainConsole console, String locator$) {
    try {
        //         System.out.println("WeblinkEditor.instantiate:locator="+locator$);
        this.console = console;
        Properties locator = Locator.toProperties(locator$);
        entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
        webLinkKey$ = locator.getProperty(JWeblinksPanel.WEB_LINK_KEY);
        System.out.println("WeblinkEditor.instantiate:1");
        Entigrator entigrator = console.getEntigrator(entihome$);
        entityLabel$ = entigrator.indx_getLabel(entityKey$);
        Sack webset = entigrator.getEntityAtKey(entityKey$);
        Core address = webset.getElementItem("web", webLinkKey$);
        addressField.setText(address.value);
        nameField.setText(address.type);
        Core login = webset.getElementItem("web.login", webLinkKey$);
        if (login != null) {
            loginField.setText(login.type);
            passwordField.setText(login.value);
        }
        Core iconCore = webset.getElementItem("web.icon", webLinkKey$);
        if (iconCore != null && iconCore.value != null) {
            try {
                String icon$ = iconCore.value;
                byte[] ba = Base64.decodeBase64(icon$);
                ImageIcon icon = new ImageIcon(ba);
                Image image = icon.getImage().getScaledInstance(24, 24, 0);
                icon.setImage(image);
                iconIcon.setIcon(icon);
            } catch (Exception ee) {
            }
        }
        requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR);
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
    return this;
}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * The default constructor./*w ww. jav a  2  s  . co m*/
 */
public JWeblinkEditor() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0 };
    gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 };
    setLayout(gridBagLayout);

    String icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "globe.png");
    byte[] ba = Base64.decodeBase64(icon$);
    ImageIcon icon = new ImageIcon(ba);
    Image image = icon.getImage().getScaledInstance(24, 24, 0);
    icon.setImage(image);
    JLabel iconLabel = new JLabel("Icon");
    c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    add(iconLabel, c);
    iconLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            showIconMenu(e);
        }
    });
    iconIcon = new JLabel();
    iconIcon.setIcon(icon);
    c_0 = new GridBagConstraints();
    c_0.anchor = GridBagConstraints.WEST;
    c_0.insets = new Insets(0, 5, 5, 0);
    c.anchor = GridBagConstraints.WEST;
    c_0.gridx = 1;
    c_0.gridy = 0;
    add(iconIcon, c_0);
    iconIcon.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            showIconMenu(e);
        }
    });
    JLabel lblName = new JLabel("Name");
    c_1 = new GridBagConstraints();
    c_1.insets = new Insets(5, 5, 5, 5);
    c_1.fill = GridBagConstraints.HORIZONTAL;
    c_1.gridx = 0;
    c_1.gridy = 1;
    add(lblName, c_1);

    nameField = new JTextField();
    c_2 = new GridBagConstraints();
    c_2.insets = new Insets(0, 5, 5, 0);
    c_2.fill = GridBagConstraints.HORIZONTAL;
    c_2.gridx = 1;
    c_2.gridy = 1;
    add(nameField, c_2);

    JLabel lblUrl = new JLabel("Address");
    c_3 = new GridBagConstraints();
    c_3.insets = new Insets(5, 5, 5, 5);
    c_3.fill = GridBagConstraints.HORIZONTAL;
    c_3.gridx = 0;
    c_3.gridy = 2;
    add(lblUrl, c_3);

    addressField = new JTextField();
    c_4 = new GridBagConstraints();
    c_4.insets = new Insets(0, 5, 5, 0);
    c_4.fill = GridBagConstraints.HORIZONTAL;
    c_4.gridx = 1;
    c_4.gridy = 2;
    add(addressField, c_4);

    JLabel lblLogin = new JLabel("Login");
    c_5 = new GridBagConstraints();
    c_5.insets = new Insets(5, 5, 5, 5);
    c_5.fill = GridBagConstraints.HORIZONTAL;
    c_5.gridx = 0;
    c_5.gridy = 3;
    add(lblLogin, c_5);
    lblLogin.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            showLoginMenu(e);
        }
    });
    loginField = new JTextField();
    c_6 = new GridBagConstraints();
    c_6.insets = new Insets(0, 5, 5, 0);
    c_6.fill = GridBagConstraints.HORIZONTAL;
    c_6.gridx = 1;
    c_6.gridy = 3;
    add(loginField, c_6);

    JLabel lblPassword = new JLabel("Password");
    c_7 = new GridBagConstraints();
    c_7.insets = new Insets(5, 5, 5, 5);
    c_7.fill = GridBagConstraints.HORIZONTAL;
    c_7.gridx = 0;
    c_7.gridy = 4;
    add(lblPassword, c_7);
    lblPassword.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            showPasswordMenu(e);
        }
    });

    passwordField = new JTextField();
    c_8 = new GridBagConstraints();
    c_8.insets = new Insets(0, 5, 5, 0);
    c_8.fill = GridBagConstraints.HORIZONTAL;
    c_8.gridx = 1;
    c_8.gridy = 4;
    add(passwordField, c_8);

    JPanel bottom = new JPanel();
    c_9 = new GridBagConstraints();
    c_9.weighty = 1;
    c_9.fill = GridBagConstraints.VERTICAL;
    c_9.gridx = 0;
    c_9.gridy = 5;
    add(bottom, c_9);
}

From source file:openblocks.yacodeblocks.DeviceReplCommController.java

private ImageIcon generateQRCode(String code) {
    Charset charset = Charset.forName("ISO-8859-1");
    CharsetEncoder encoder = charset.newEncoder();
    byte[] b = null;
    try {//from w w  w  . ja  v  a  2s.  c  o  m
        // Convert a string to ISO-8859-1 bytes in a ByteBuffer
        ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(code));
        b = bbuf.array();
    } catch (CharacterCodingException e) {
        System.out.println(e.getMessage());
    }

    String data = null;
    try {
        data = new String(b, "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        System.out.println(e.getMessage());
    }

    // get a byte matrix for the data
    BitMatrix matrix = null;
    int h = 200;
    int w = 200;
    com.google.zxing.Writer writer = new QRCodeWriter();
    try {
        matrix = writer.encode(data, com.google.zxing.BarcodeFormat.QR_CODE, w, h);
        ImageIcon qrcode = new ImageIcon();
        qrcode.setImage(MatrixToImageWriter.toBufferedImage(matrix));
        return qrcode;
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return null;
}