Example usage for javax.swing JLabel addMouseListener

List of usage examples for javax.swing JLabel addMouseListener

Introduction

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

Prototype

public synchronized void addMouseListener(MouseListener l) 

Source Link

Document

Adds the specified mouse listener to receive mouse events from this component.

Usage

From source file:Main.java

public PopupMenu() {
    super(BoxLayout.Y_AXIS);
    final JPopupMenu menu = new JPopupMenu("Options");
    for (int i = 1; i < 20; i++)
        menu.add(new JMenuItem("Option" + i));

    JLabel clickMe = new JLabel("ClickMe");
    clickMe.setAlignmentX(RIGHT_ALIGNMENT);
    clickMe.addMouseListener(new MouseAdapter() {
        @Override//  w  w  w  . ja  v  a  2 s.co  m
        public void mouseClicked(MouseEvent e) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    add(clickMe);
}

From source file:Main.java

public Main() {
    Icon icon = UIManager.getIcon("html.pendingImage");
    JTabbedPane jtb = new JTabbedPane();

    JPanel jplInnerPanel1 = createInnerPanel("Tab 1: Tooltip and Icon");
    jtb.addTab("One", icon, jplInnerPanel1, "Tab 1");
    jtb.setSelectedIndex(0);//from  w w w  .  j  av  a2s  .  c  om

    JPanel jplInnerPanel2 = createInnerPanel("Tab 2: Icon only");
    jtb.addTab("Two", icon, jplInnerPanel2);

    JPanel jplInnerPanel3 = createInnerPanel("Tab 3: Tooltip and Icon");
    jtb.addTab("Three", icon, jplInnerPanel3, "Tab 3");

    JPanel jplInnerPanel4 = createInnerPanel("Tab 4: Text only");
    jtb.addTab("Four", jplInnerPanel4);

    menu.add(new JMenuItem("Item 1"));
    menu.add(new JMenuItem("Item 2"));

    JLabel tab4Label = new JLabel();
    tab4Label.setText("Four");
    jtb.setTabComponentAt(3, tab4Label);
    tab4Label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            jtb.getModel().setSelectedIndex(3);
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    setLayout(new GridLayout());
    add(jtb);
}

From source file:com.antelink.sourcesquare.gui.view.CopyrightPanel.java

private JLabel createJLabelWithHyperlink(String text, final String href) {
    JLabel label = new JLabel("<html><a href=\"\">" + text + "<a/></html>");
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseListener() {

        @Override/*from   w w w  .  java2 s .c  o m*/
        public void mouseReleased(MouseEvent arg0) {
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
        }

        @Override
        public void mouseExited(MouseEvent arg0) {
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URI(href));
            } catch (IOException e) {
                logger.error("Error opening the browser", e);
            } catch (URISyntaxException e) {
                logger.error("Error opening the browser", e);
            }
        }
    });
    return label;
}

From source file:de.iew.imageupload.widgets.ContentPane.java

public void registerImageFile(File file) {
    try {//from  www .j  a v a 2 s .  co  m
        ImageIcon imageIcon = new ImageIcon(file.getAbsolutePath());
        JLabel imageLabel = new JLabel(imageIcon, JLabel.CENTER);
        imageLabel.setPreferredSize(new Dimension(100, 100));
        imageLabel.setSize(new Dimension(100, 100));
        imageLabel.addMouseListener(this.imageMouseClickHandler);
        imageLabel.setBackground(Color.WHITE);
        imageLabel.setBorder(new EmptyBorder(10, 10, 10, 10));
        imageLabel.putClientProperty("Image File", file);

        this.imageGridPane.add(imageLabel);
        this.imageGridPane.revalidate();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.willwinder.ugs.nbp.core.services.SettingsChangedNotificationService.java

private JComponent createRestartNotificationDetails() {
    JPanel panel = new JPanel(new BorderLayout(10, 10));
    panel.setOpaque(false);/*w  w w  .  j  a va 2s .  co  m*/

    JLabel label = new JLabel(Localization.getString("platform.window.restart.changed.settings")); //NOI18N
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    panel.add(label, BorderLayout.CENTER);

    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (null != restartNotification) {
                restartNotification.clear();
                restartNotification = null;
            }

            LifecycleManager.getDefault().markForRestart();
            LifecycleManager.getDefault().exit();
        }
    });
    return panel;
}

From source file:be.tutul.naheulcraft.launcher.auth.LogInForm.java

private void createInterface() {
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = 2;/*from  ww  w.ja  va2  s.c o m*/
    constraints.gridx = 0;
    constraints.gridy = -1;
    constraints.weightx = 1.0D;

    add(Box.createGlue());

    JLabel usernameLabel = new JLabel("Pseudo : ");
    Font labelFont = usernameLabel.getFont().deriveFont(1);
    Font smalltextFont = usernameLabel.getFont().deriveFont(labelFont.getSize() - 2.0F);

    usernameLabel.setFont(labelFont);
    add(usernameLabel, constraints);
    add(this.usernameField, constraints);

    add(Box.createVerticalStrut(10), constraints);

    JLabel passwordLabel = new JLabel("Mot de passe :");
    passwordLabel.setFont(labelFont);
    add(passwordLabel, constraints);
    add(this.passwordField, constraints);

    JLabel forgotPasswordLabel = new JLabel("(oubli ?)");
    forgotPasswordLabel.setCursor(new Cursor(12));
    forgotPasswordLabel.setFont(smalltextFont);
    forgotPasswordLabel.setHorizontalAlignment(4);
    forgotPasswordLabel.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            try {
                Util.openLink(Variables.lost);
            } catch (Exception e1) {
                LogInForm.this.login.getLauncher().getLogger()
                        .error("Impossible d'ouvrir le lien pour les logins oublis");
                JOptionPane.showMessageDialog(LogInForm.this.login.getLauncher().getPanel(),
                        "Impossible d'ouvrir la page\nRendez-vous sur le site de NaheulCraft pour rcuprer vos identifiants",
                        "Impossible d'ouvrir l'URL", 0);
            }
        }
    });
    add(forgotPasswordLabel, constraints);

    createUserDropdownPanel(labelFont);
    add(this.userDropdownPanel, constraints);

    add(Box.createVerticalStrut(10), constraints);
}

From source file:com.github.cric.app.ui.SettingPanel.java

private Component helpLabel() {

    JLabel help = new JLabel(HELP_TEXT);
    help.addMouseListener(new MouseAdapter() {

        @Override/*from  w  w w. jav  a  2 s  .  c om*/
        public void mouseEntered(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

        @Override
        public void mouseExited(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(HELP_PAGE);
                } catch (Exception ex) {
                    LOG.warn("unable to open link", ex);
                }
            }
        }
    });
    return help;
}

From source file:es.emergya.ui.base.Message.java

private void inicializar(final String texto) {
    log.trace("inicializar(" + texto + ")");
    final Message message_ = this;

    SwingUtilities.invokeLater(new Runnable() {

        @Override//  w  w  w.j  a va2 s .c om
        public void run() {
            log.trace("Sacamos un nuevo mensaje: " + texto);
            JDialog frame = new JDialog(window.getFrame(), true);
            frame.setUndecorated(true);
            frame.getContentPane().setBackground(Color.WHITE);
            frame.setLocation(150, window.getHeight() - 140);
            frame.setSize(new Dimension(window.getWidth() - 160, 130));
            frame.setName("Incoming Message");
            frame.setBackground(Color.WHITE);
            frame.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, color));

            frame.setLayout(new BorderLayout());
            if (font != null)
                frame.setFont(font);

            JLabel icon = new JLabel(new ImageIcon(this.getClass().getResource("/images/button-ok.png")));
            icon.setToolTipText("Cerrar");

            icon.removeMouseListener(null);
            icon.addMouseListener(new Cerrar(frame, message_));

            JLabel text = new JLabel(texto);
            text.setBackground(Color.WHITE);
            text.setForeground(Color.BLACK);
            frame.add(text, BorderLayout.WEST);
            frame.add(icon, BorderLayout.EAST);

            frame.setVisible(true);
        }
    });
}

From source file:dpcs.About.java

public About() {
    setIconImage(Toolkit.getDefaultToolkit().getImage(About.class.getResource("/graphics/Icon.png")));
    setResizable(false);//from w  w w.  ja  v  a  2 s .c  o  m
    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:Interface.ResultadoJanela.java

public ResultadoJanela(List<Resultado> tar, List<Resultado> jac, List<Resultado> och, List<Resultado> sbi) {
    //  super("Resultado");
    CategoryDataset dataset;//from ww w.  ja v  a  2 s  . c  o  m

    //---------------------gerando resultados tarantula-------------------------------------
    dataset = gerarDataset(tar, jac, och, sbi);
    JFreeChart chart = gerarGrafico(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);

    JLabel lAjuda = new JLabel("Ajuda", JLabel.RIGHT);
    lAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icone_informacao.gif"))); // NOI18N
    lAjuda.setPreferredSize(new Dimension(50, 50));
    lAjuda.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            lAjudaMouseClicked(evt);
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(lAjuda, BorderLayout.BEFORE_FIRST_LINE);
    panel.add(chartPanel, BorderLayout.LINE_START);
    JLabel lTabela = new JLabel("Tabela de Resultados", JLabel.CENTER);
    panel.add(lTabela, BorderLayout.SOUTH);

    JTable table = new JTable(criarValores(tar, jac, och, sbi), criarColunas());

    // Adiciona o JTable dentro do painel
    JScrollPane scrollPane = new JScrollPane(table);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    panel.add(scrollPane, BorderLayout.SOUTH);

    JFrame frame = new JFrame();
    frame.setTitle("JLoc - Resultado");
    frame.setVisible(true);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);
}