Example usage for javax.swing JLabel setIcon

List of usage examples for javax.swing JLabel setIcon

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The icon this component will display.")
public void setIcon(Icon icon) 

Source Link

Document

Defines the icon this component will display.

Usage

From source file:ca.phon.app.query.report.ReportTreeCellRenderer.java

@Override
public Component getTreeCellRendererComponent(JTree arg0, Object arg1, boolean arg2, boolean arg3, boolean arg4,
        int arg5, boolean arg6) {
    JLabel lbl = (JLabel) super.getTreeCellRendererComponent(arg0, arg1, arg2, arg3, arg4, arg5, arg6);

    Section section = (Section) arg1;/*w w  w  .  j  a  v a2  s  . co m*/

    if (arg1 == arg0.getModel().getRoot()) {
        lbl.setIcon(rptIcon);
    } else {
        lbl.setIcon(icons.get(section.getClass()));
    }

    String lblText = StringUtils.strip(section.getName());
    if (lblText == null || lblText.length() == 0) {
        lblText = "<html><i>Untitled</i></html>";
    }
    lbl.setText(lblText);

    //      if(arg1 instanceof ReportDesign) {
    //         ReportDesign report = (ReportDesign)arg1;
    //         lbl.setText(report.getName());
    //         lbl.setIcon(rptIcon);
    //      } else {
    //         Section section = (Section)arg1;
    //         lbl.setIcon(icons.get(section.getClass()));
    //         
    //         
    //         lbl.setText(section.getName());
    ////         if(section instanceof Group) {
    ////            lbl.setText("Group : " + section.getName());
    ////         } else {
    ////            lbl.setText("Section : " + section.getName());
    ////         }
    //      }

    return lbl;
}

From source file:MainClass.java

public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JLabel) {
        JLabel label = (JLabel) comp;
        if (t.isDataFlavorSupported(flavors[0])) {
            try {
                image = (Image) t.getTransferData(flavors[0]);
                ImageIcon icon = new ImageIcon(image);
                label.setIcon(icon);
                return true;
            } catch (UnsupportedFlavorException ignored) {
            } catch (IOException ignored) {
            }//from   w w w .j a va  2 s  .c o  m
        }
    } else if (comp instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) comp;
        if (t.isDataFlavorSupported(flavors[0])) {
            try {
                image = (Image) t.getTransferData(flavors[0]);
                ImageIcon icon = new ImageIcon(image);
                button.setIcon(icon);
                return true;
            } catch (UnsupportedFlavorException ignored) {
            } catch (IOException ignored) {
            }
        }
    }
    return false;
}

From source file:task5.deneme.java

private JFrame get_MYIMAGE() {
    JFrame frame = new JFrame("picture");
    frame.setSize(img.getWidth(), img.getHeight());
    JLabel l = new JLabel();
    l.setSize(img.getWidth(), img.getHeight());
    l.setIcon((new ImageIcon(img)));
    frame.add(l);//from  ww  w. j av  a2  s.  com
    frame.setVisible(true);
    return frame;
}

From source file:generadorqr.jifrGestionArticulos.java

public static void MostrarVisualizador(JLabel Pantalla, String RutaDestino) {
    try {//from  w w  w.  j a  va  2s.c om
        Image capturarImgSoloLectura = ImageIO.read(new File(RutaDestino));
        Image obtenerImagen = capturarImgSoloLectura.getScaledInstance(Pantalla.getPreferredSize().width,
                Pantalla.getPreferredSize().height - 10, Image.SCALE_SMOOTH);
        Icon iconoEscalado = new ImageIcon(obtenerImagen);
        Pantalla.setIcon(iconoEscalado);
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }
}

From source file:DragImage.java

public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JLabel) {
        JLabel label = (JLabel) comp;
        if (t.isDataFlavorSupported(flavors[0])) {
            try {
                image = (Image) t.getTransferData(flavors[0]);
                ImageIcon icon = new ImageIcon(image);
                label.setIcon(icon);
                return true;
            } catch (UnsupportedFlavorException ignored) {
            } catch (IOException ignored) {
            }/*from w  w w.j  av  a  2s  .c o  m*/
        }
    }
    return false;
}

From source file:gov.nih.nci.nbia.StandaloneDM.java

private JPanel constructLoginPanel() {
    JPanel contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(null);//from   ww  w.  jav a 2  s. c o  m

    JLabel lblNewLabel_2 = new JLabel();
    lblNewLabel_2.setBounds(20, 11, 100, 100);
    contentPane.add(lblNewLabel_2);
    ImageIcon iconLogo = new ImageIcon("Images/global.logo");
    lblNewLabel_2.setIcon(iconLogo);
    statusLbl = new JLabel(
            "<html>Some or all of the images you are about to download are from<br>private collection(s). Please log in first.</html>");
    contentPane.add(statusLbl);
    statusLbl.setBounds(110, 11, 500, 42);
    JLabel lblNewLabel = new JLabel("User Name");
    contentPane.add(lblNewLabel);
    lblNewLabel.setBounds(110, 79, 77, 31);

    userNameFld = new JTextField();
    contentPane.add(userNameFld);
    userNameFld.setBounds(187, 75, 333, 36);
    userNameFld.setColumns(10);

    JButton submitBtn = new JButton(SubmitBtnLbl);
    submitBtn.addActionListener(new BtnListener());
    contentPane.add(submitBtn);
    submitBtn.setBounds(249, 200, 139, 36);

    passwdFld = new JPasswordField();
    contentPane.add(passwdFld);
    passwdFld.setBounds(187, 129, 333, 36);

    userNameFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            passwdFld.requestFocus();
        }
    });

    passwdFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            userId = userNameFld.getText();
            password = passwdFld.getText();
            if ((userId.length() < 1) || (password.length() < 1)) {
                statusLbl.setText("Please enter a valid user name and password.");
                statusLbl.setForeground(Color.red);
            } else
                submitUserCredential(userId, password);
        }
    });

    JLabel lblNewLabel_1 = new JLabel("Password");
    contentPane.add(lblNewLabel_1);
    lblNewLabel_1.setBounds(110, 129, 77, 36);

    return contentPane;
}

From source file:net.sf.taverna.raven.plugins.ui.CheckForUpdatesDialog.java

private void initComponents() {
    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Message saying that updates are available
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.setBorder(/*from  ww w.j  a  va  2  s.  com*/
            new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(EtchedBorder.LOWERED)));
    JLabel message = new JLabel(
            "<html><body>Updates are available for some Taverna components. To review and <br>install them go to 'Updates and plugins' in the 'Advanced' menu.</body><html>");
    message.setFont(baseFont.deriveFont(12f));
    message.setBorder(new EmptyBorder(5, 5, 5, 5));
    message.setIcon(UpdatesAvailableIcon.updateIcon);
    messagePanel.add(message, BorderLayout.CENTER);

    // Buttons
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton okButton = new JButton("OK"); // we'll check for updates again in 2 weeks
    okButton.setFont(baseFont);
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    buttonsPanel.add(okButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(messagePanel, BorderLayout.CENTER);
    getContentPane().add(buttonsPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}

From source file:dpcs.About.java

public About() {
    setIconImage(Toolkit.getDefaultToolkit().getImage(About.class.getResource("/graphics/Icon.png")));
    setResizable(false);/*from ww  w .ja  va2s.  com*/
    setType(Type.UTILITY);
    setTitle("About");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 540, 400);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
    try {
        InputStreamReader reader2 = new InputStreamReader(
                getClass().getResourceAsStream("/others/app-version.txt"));
        String tmp = IOUtils.toString(reader2);
        AppVersion = Double.parseDouble(tmp);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    JButton btnGitHub = new JButton("GitHub");
    btnGitHub.setToolTipText("Access Droid PC Suite github repository");
    btnGitHub.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URL("https://github.com/kvsjxd/Droid-PC-Suite/").toURI());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    btnGitHub.setBounds(369, 295, 111, 25);
    contentPane.add(btnGitHub);

    JLabel lblMyFriend4 = new JLabel("Gulati-kun");
    lblMyFriend4.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend4.setBounds(25, 266, 242, 24);
    contentPane.add(lblMyFriend4);

    JLabel lblMyFriend3 = new JLabel("Anil-kun");
    lblMyFriend3.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend3.setBounds(25, 242, 242, 24);
    contentPane.add(lblMyFriend3);

    JLabel lblMyFriend2 = new JLabel("Suri-kun");
    lblMyFriend2.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend2.setBounds(25, 217, 242, 24);
    contentPane.add(lblMyFriend2);

    JLabel lblApplicationVersion = new JLabel("Version: " + AppVersion);
    lblApplicationVersion.setFont(new Font("Dialog", Font.BOLD, 14));
    lblApplicationVersion.setBounds(382, 16, 132, 18);
    contentPane.add(lblApplicationVersion);

    JLabel lblForMyOther = new JLabel("For my other Android stuff visit me on XDA - Developers (@kvsjxd)");
    lblForMyOther.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URL(
                        "http://forum.xda-developers.com/member.php?s=82fb1dacfee601c8f79084b30d57d5a2&u=5640594")
                                .toURI());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblForMyOther.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblForMyOther.setForeground(Color.BLACK);
        }
    });
    lblForMyOther.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblForMyOther.setBounds(25, 321, 502, 24);
    contentPane.add(lblForMyOther);

    JLabel lblMySensei2 = new JLabel("Karun Sensei");
    lblMySensei2.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMySensei2.setBounds(25, 120, 242, 24);
    contentPane.add(lblMySensei2);

    JLabel lblMySensei1 = new JLabel("Prashotam Sensei");
    lblMySensei1.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMySensei1.setBounds(25, 98, 242, 24);
    contentPane.add(lblMySensei1);

    JLabel lblDaretobe = new JLabel("D4r3T0B3");
    lblDaretobe.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblDaretobe.setBounds(25, 194, 242, 24);
    contentPane.add(lblDaretobe);

    JLabel label_9 = new JLabel("");
    label_9.setToolTipText("This variation of android robot is created using Androidify");
    label_9.setIcon(new ImageIcon(About.class.getResource("/graphics/Droidrobot.png")));
    label_9.setBounds(334, 50, 180, 270);
    contentPane.add(label_9);

    JLabel lblDeveloper = new JLabel("Developer");
    lblDeveloper.setFont(new Font("Dialog", Font.BOLD, 16));
    lblDeveloper.setBounds(25, 12, 233, 24);
    contentPane.add(lblDeveloper);

    JLabel lblMrAleksandarDespotovski_shi = new JLabel("Aleksandar Despotovski-shi");
    lblMrAleksandarDespotovski_shi.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMrAleksandarDespotovski_shi.setBounds(25, 169, 242, 24);
    contentPane.add(lblMrAleksandarDespotovski_shi);

    JLabel lblMyname = new JLabel("Karanvir Singh");
    lblMyname.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try {
                Desktop.getDesktop().browse(new URL(
                        "http://forum.xda-developers.com/member.php?s=82fb1dacfee601c8f79084b30d57d5a2&u=5640594")
                                .toURI());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            lblMyname.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblMyname.setForeground(Color.RED);
        }
    });
    lblMyname.setForeground(Color.RED);
    lblMyname.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 16));
    lblMyname.setBounds(25, 36, 242, 24);
    contentPane.add(lblMyname);

    JLabel lblMyFriend1 = new JLabel("My friend - Chetan-kun");
    lblMyFriend1.setFont(new Font("Dialog", Font.PLAIN, 15));
    lblMyFriend1.setBounds(25, 145, 242, 24);
    contentPane.add(lblMyFriend1);

    JLabel label_6 = new JLabel("Special thanks to");
    label_6.setForeground(UIManager.getColor("OptionPane.questionDialog.titlePane.shadow"));
    label_6.setFont(new Font("Dialog", Font.BOLD, 16));
    label_6.setBounds(25, 71, 240, 25);
    contentPane.add(label_6);

    JLabel lblGoogle = new JLabel(
            "Android, android green colored robot are trademarks of Google, Inc. We are not affliated with Google, Inc. in any way.");
    lblGoogle.setHorizontalAlignment(SwingConstants.LEFT);
    lblGoogle.setFont(new Font("Dialog", Font.PLAIN, 8));
    lblGoogle.setBounds(25, 341, 514, 24);
    contentPane.add(lblGoogle);
}

From source file:musiccrawler.App.java

private JPanel loadingPanel() {
    JPanel panel = new JPanel();
    BoxLayout layoutMgr = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
    panel.setLayout(layoutMgr);// w  w  w .j  av a2s.  c  o m
    ClassLoader cldr = this.getClass().getClassLoader();
    java.net.URL imageURL = cldr.getResource("image/ajax-loader.gif");
    ImageIcon imageIcon = new ImageIcon(imageURL);
    JLabel iconLabel = new JLabel();
    iconLabel.setIcon(imageIcon);
    imageIcon.setImageObserver(iconLabel);
    JLabel label = new JLabel("Loading...");
    panel.add(iconLabel);
    panel.add(label);
    return panel;
}

From source file:SplitPaneTest.java

public SplitPaneFrame() {
    setTitle("SplitPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // set up components for planet names, images, descriptions

    final JList planetList = new JList(planets);
    final JLabel planetImage = new JLabel();
    final JTextArea planetDescription = new JTextArea();

    planetList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            Planet value = (Planet) planetList.getSelectedValue();

            // update image and description

            planetImage.setIcon(value.getImage());
            planetDescription.setText(value.getDescription());
        }/*from  w w w  .  ja v  a2 s .co m*/
    });

    // set up split panes

    JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage);

    innerPane.setContinuousLayout(true);
    innerPane.setOneTouchExpandable(true);

    JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane, planetDescription);

    add(outerPane, BorderLayout.CENTER);
}