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:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

/**
 * Register tooltip for {@link javax.swing.JLabel}.
 * Tooltip is displayed when the user hovers over a label
 * ToolTip text is taken from {@link javax.swing.JComponent#getToolTipText()}.
 *
 * @param lbl Label to register// w ww  .java  2 s .  c  o m
 */
public void registerTooltip(final JLabel lbl) {
    lbl.removeMouseListener(componentMouseListener);
    lbl.addMouseListener(componentMouseListener);
}

From source file:com.github.cmisbox.ui.BaseFrame.java

public BaseFrame() {
    super(AWTUtilitiesWrapper.isTranslucencyCapable(BaseFrame.gc) ? BaseFrame.gc : null);
    this.log = LogFactory.getLog(this.getClass());

    this.gradient = false;
    this.setUndecorated(true);
    this.mainPanel = new JPanel(new GridBagLayout()) {

        private static final long serialVersionUID = 1035974033526970010L;

        protected void paintComponent(Graphics g) {
            if ((g instanceof Graphics2D) && BaseFrame.this.gradient) {
                final int R = 0;
                final int G = 0;
                final int B = 0;

                Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 192), this.getWidth(),
                        this.getHeight(), new Color(R, G, B, 255), true);
                Graphics2D g2d = (Graphics2D) g;
                g2d.setPaint(p);/*  www  .j  a  va2 s.c om*/
                g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
            } else {
                super.paintComponent(g);
            }
        }
    };

    this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    GridBagConstraints gbc = new GridBagConstraints();

    this.mainPanel.setDoubleBuffered(false);
    this.mainPanel.setOpaque(false);
    this.mainPanel.setBorder(BorderFactory.createLineBorder(Color.white));

    JLabel title = new JLabel(this.getWindowTitle(), SwingConstants.CENTER);
    title.setForeground(Color.white);

    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 100;

    this.mainPanel.add(title, gbc);

    Image closeImg = this.getImage("images/application-exit.png", 32, 32);
    JLabel close = new JLabel(new ImageIcon(closeImg), SwingConstants.RIGHT);

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 2;
    gbc.weightx = 0;

    this.mainPanel.add(close, gbc);

    close.addMouseListener(this.closeAdapter);

    this.getContentPane().add(this.mainPanel, BorderLayout.CENTER);

    this.initComponents();

    this.pack();

    this.mainPanel.setOpaque(!this.gradient);
    if (!this.gradient) {
        this.mainPanel.setBackground(new Color(0, 0, 0, 208));
    }

    this.setLocationRelativeTo(null);
    AWTUtilitiesWrapper.setWindowOpaque(this, false);
    this.setVisible(true);
    this.setAlwaysOnTop(true);

}

From source file:Main.java

public Main() {
    mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    mainPanel.setLayout(null);// w w w .j a  v a2s.  c  o  m

    MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
    for (int i = 0; i < LABEL_STRINGS.length; i++) {
        JLabel label = new JLabel(LABEL_STRINGS[i], SwingConstants.CENTER);
        label.setSize(new Dimension(LBL_WIDTH, LBL_HEIGHT));
        label.setOpaque(true);
        Random random = new Random();
        label.setLocation(random.nextInt(WIDTH - LBL_WIDTH), random.nextInt(HEIGHT - LBL_HEIGHT));
        label.setBackground(
                new Color(150 + random.nextInt(105), 150 + random.nextInt(105), 150 + random.nextInt(105)));
        label.addMouseListener(myMouseAdapter);
        label.addMouseMotionListener(myMouseAdapter);

        mainPanel.add(label);
    }
}

From source file:org.apache.taverna.activities.xpath.ui.contextualview.XPathActivityMainContextualView.java

@Override
public JComponent getMainFrame() {
    jpMainPanel = new JPanel(new GridBagLayout());
    jpMainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 2, 4, 2),
            BorderFactory.createEmptyBorder()));

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.weighty = 0;//from  www  . j ava2  s.c o m

    // --- XPath Expression ---

    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(5, 5, 5, 5);
    JLabel jlXPathExpression = new JLabel("XPath Expression:");
    jlXPathExpression.setFont(jlXPathExpression.getFont().deriveFont(Font.BOLD));
    jpMainPanel.add(jlXPathExpression, c);

    c.gridx++;
    c.weightx = 1.0;
    tfXPathExpression = new JTextField();
    tfXPathExpression.setEditable(false);
    jpMainPanel.add(tfXPathExpression, c);

    // --- Label to Show/Hide Mapping Table ---

    final JLabel jlShowHideNamespaceMappings = new JLabel("Show namespace mappings...");
    jlShowHideNamespaceMappings.setForeground(Color.BLUE);
    jlShowHideNamespaceMappings.setCursor(new Cursor(Cursor.HAND_CURSOR));
    jlShowHideNamespaceMappings.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            spXPathNamespaceMappings.setVisible(!spXPathNamespaceMappings.isVisible());
            jlShowHideNamespaceMappings.setText(
                    (spXPathNamespaceMappings.isVisible() ? "Hide" : "Show") + " namespace mappings...");
            thisContextualView.revalidate();
        }
    });

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    jpMainPanel.add(jlShowHideNamespaceMappings, c);

    // --- Namespace Mapping Table ---

    xpathNamespaceMappingsTableModel = new DefaultTableModel() {
        /**
         * No cells should be editable
         */
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (false);
        }
    };
    xpathNamespaceMappingsTableModel.addColumn("Namespace Prefix");
    xpathNamespaceMappingsTableModel.addColumn("Namespace URI");

    jtXPathNamespaceMappings = new JTable();
    jtXPathNamespaceMappings.setModel(xpathNamespaceMappingsTableModel);
    jtXPathNamespaceMappings.setPreferredScrollableViewportSize(new Dimension(200, 90));
    // TODO - next line is to be enabled when Taverna is migrated to Java
    // 1.6; for now it's fine to run without this
    // jtXPathNamespaceMappings.setFillsViewportHeight(true); // makes sure
    // that when the dedicated area is larger than the table, the latter is
    // stretched vertically to fill the empty space

    jtXPathNamespaceMappings.getColumnModel().getColumn(0).setPreferredWidth(20); // set
    // relative
    // sizes of
    // columns
    jtXPathNamespaceMappings.getColumnModel().getColumn(1).setPreferredWidth(300);

    c.gridy++;
    spXPathNamespaceMappings = new JScrollPane(jtXPathNamespaceMappings);
    spXPathNamespaceMappings.setVisible(false);
    jpMainPanel.add(spXPathNamespaceMappings, c);

    // populate the view with values
    refreshView();

    return jpMainPanel;
}

From source file:com.ssn.ui.custom.component.SSNImageThumbnailControl.java

public SSNImageThumbnailControl getSsnImageThumbnailControl(String imagePath, int index) {
    //this.setLayout();
    iF = 0;//from  w  w w  . j a  va2 s .c o m
    BufferedImage thumbImg1 = null;
    this.index = index;
    BufferedImage image;
    String[] videoSupported = SSNConstants.SSN_VIDEO_FORMAT_SUPPORTED;
    final List<String> videoSupportedList = Arrays.asList(videoSupported);
    try {

        // add code to check file is video or image  if video then write code to create thumbnail 
        String fileExtention = imagePath.substring(imagePath.lastIndexOf(".") + 1, imagePath.length());
        if (videoSupportedList.contains(fileExtention.toUpperCase())) {

            IMediaReader reader = null;
            try {

                if (true) {
                    reader = ToolFactory.makeReader(imagePath);
                    reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
                    reader.addListener(new MediaListenerAdapter() {
                        @Override
                        public void onVideoPicture(IVideoPictureEvent event) {
                            setVideoFrame(event.getImage());
                            iF++;
                        }

                    });
                    while (reader.readPacket() == null && iF == 0)
                        ;
                    thumbImg1 = SSNHelper.resizeImage(getVideoFrame(), 50, 50);
                }
            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                if (reader != null)
                    reader.close();
            }
        } else {
            image = ImageIO.read(new File(imagePath));
            thumbImg1 = SSNHelper.resizeImage(image, 50, 50);
        }

    } catch (IOException ex) {
        Logger.getLogger(SSNImageThumbnailControl.class.getName()).log(Level.SEVERE, null, ex);
    }
    ImageIcon imageIcon = new ImageIcon(thumbImg1);
    JLabel thumbnailLabel = new JLabel(imageIcon, SwingConstants.HORIZONTAL);
    JLabel closeLabel = new JLabel(new ImageIcon(getClass().getResource("/icon/remove-icon.png")),
            SwingConstants.HORIZONTAL);
    closeLabel.setFocusable(true);
    closeLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    this.add(thumbnailLabel);
    this.add(closeLabel);
    closeLabel.addMouseListener(this);

    this.setFocusable(true);
    this.setSize(new Dimension(50, 50));
    this.setBackground(new Color(0, 0, 0, 1));

    return this;
}

From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java

private void initLabelLink(JLabel label, final String url) {
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (event.getClickCount() > 0) {
                if (Desktop.isDesktopSupported()) {
                    Desktop desktop = Desktop.getDesktop();
                    try {
                        URI uri = new URI(url);
                        desktop.browse(uri);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }//from  w w w .  java 2s .c  o  m
                }
            }
        }
    });
}

From source file:ca.phon.app.session.editor.view.segmentation.SegmentationEditorView.java

private void updateParticipantPanel() {
    participantPanel.removeAll();/*  w  ww .j  a va 2s .  com*/

    // setup layout
    String colLayout = "fill:default";
    String rowLayout = "pref, 5px";
    for (int i = 0; i <= getEditor().getSession().getParticipantCount(); i++) {
        rowLayout += ", pref, 5px";
    }
    FormLayout layout = new FormLayout(colLayout, rowLayout);
    participantPanel.setLayout(layout);
    CellConstraints cc = new CellConstraints();
    int currentRow = 1;

    String ksStr = (OSInfo.isMacOs() ? "\u2318" : "CTRL +") + "0";
    PhonUIAction noPartSegmentAct = new PhonUIAction(this, "performSegmentation", null);
    noPartSegmentAct.putValue(Action.NAME, ksStr + " speaker undefined");

    // setup labels to be used like buttons
    String segMsg = "Click name to create a new record:";
    JLabel segLbl = new JLabel(segMsg);

    participantPanel.add(segLbl, cc.xy(1, currentRow));
    currentRow += 2;

    JLabel noPartLbl = new JLabel();
    String noPartMsg = ksStr + " <no speaker>";
    noPartLbl.setText(noPartMsg);
    noPartLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    noPartLbl.addMouseListener(new SegmentLabelMouseHandler());
    noPartLbl.setOpaque(false);
    participantPanel.add(noPartLbl, cc.xy(1, currentRow));
    currentRow += 2;

    final Session session = getEditor().getSession();
    int pIdx = 1;
    for (Participant p : session.getParticipants()) {
        ksStr = (OSInfo.isMacOs() ? "\u2318" : "CTRL +") + pIdx;

        final NewSegmentAction segmentAction = new NewSegmentAction(getEditor(), this, p);
        segmentAction.putValue(Action.NAME, ksStr + " " + p.toString());

        JLabel participantLbl = new JLabel();
        String participantStr = ksStr + " " + (p.getName() != null ? p.getName() : p.getId());
        participantLbl.setText(participantStr);
        participantLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        participantLbl.addMouseListener(new SegmentLabelMouseHandler(p));
        participantLbl.setOpaque(false);
        participantPanel.add(participantLbl, cc.xy(1, currentRow));
        currentRow += 2;

        pIdx++;
    }
}

From source file:gdt.jgui.tool.JIconSelector.java

/**
 * Create the context./*from   www. ja  va2 s.  c om*/
 * @param console the main console.
 * @param locator$ the locator string.
 * @return the procedure context.
 */
@Override
public JContext instantiate(JMainConsole console, String locator$) {
    this.console = console;
    try {
        panel.removeAll();
        Properties locator = Locator.toProperties(locator$);
        entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
        entityLabel$ = locator.getProperty(EntityHandler.ENTITY_LABEL);
        requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR);
        //          System.out.println("IconSelector:instantiate:locator="+locator$);
        Entigrator entigrator = console.getEntigrator(entihome$);
        String icons$ = entigrator.ent_getHome(Entigrator.ICONS);
        File icons = new File(icons$);
        File[] fa = icons.listFiles();
        if (fa == null)
            return this;
        ImageIcon icon;
        JLabel label;
        Image img;
        for (File aFa : fa) {
            icon = new ImageIcon(aFa.getPath());
            img = icon.getImage();
            img = img.getScaledInstance(smallIcon, smallIcon, java.awt.Image.SCALE_SMOOTH);
            icon = new ImageIcon(img);
            label = new JLabel();
            label.setIcon(icon);
            label.setName(aFa.getName());
            label.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent me) {
                    try {
                        JLabel label = (JLabel) me.getSource();
                        icon$ = label.getName();
                        byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                        String responseLocator$ = new String(ba, "UTF-8");
                        responseLocator$ = Locator.append(responseLocator$, ICON, icon$);
                        JConsoleHandler.execute(JIconSelector.this.console, responseLocator$);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });

            panel.add(label);
        }

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

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper factory method for creating clickable links.
 *
 * @param linkText//from  ww w  . j  a  v a2 s  .c o m
 *         a string that will be displayed as a link
 * @param action
 *         the action performed at click
 * @return the link component
 */
protected JComponent createLink(String linkText, final Runnable action) {
    Preconditions.checkNotNull(linkText);
    Preconditions.checkNotNull(action);

    JLabel link = new JLabel("<html><a href=''>" + linkText + "</a></html>");
    link.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale()));
    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
    link.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            action.run();
        }
    });
    return link;
}

From source file:JXTransformer.java

private JPanel createDemoPanel() {
        JPanel buttonPanel = new JPanel(new GridLayout(3, 2));
        TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !");
        Font titleFont = titledBorder.getTitleFont();
        titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10));
        titledBorder.setTitleJustification(TitledBorder.CENTER);
        buttonPanel.setBorder(titledBorder);
        JButton b = new JButton("JButton");
        b.setPreferredSize(new Dimension(100, 50));
        buttonPanel.add(createTransformer(b));

        Vector<String> v = new Vector<String>();
        v.add("One");
        v.add("Two");
        v.add("Three");
        JList list = new JList(v);
        buttonPanel.add(createTransformer(list));

        buttonPanel.add(createTransformer(new JCheckBox("JCheckBox")));

        JSlider slider = new JSlider(0, 100);
        slider.setLabelTable(slider.createStandardLabels(25, 0));
        slider.setPaintLabels(true);//  w w  w . j  ava2  s .co  m
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(10);
        buttonPanel.add(createTransformer(slider));

        buttonPanel.add(createTransformer(new JRadioButton("JRadioButton")));
        final JLabel label = new JLabel("JLabel");
        label.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() + 10));
            }

            public void mouseExited(MouseEvent e) {
                Font font = label.getFont();
                label.setFont(font.deriveFont(font.getSize2D() - 10));
            }
        });
        buttonPanel.add(createTransformer(label));

        return buttonPanel;
    }