Java Code Examples for javax.swing.JPanel.addMouseListener()

The following are Jave code examples for showing how to use addMouseListener() of the javax.swing.JPanel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LivroJavaComoProgramar10Edicao   File: MouseTrackerFrame.java   View Source Code Vote up 6 votes
public MouseTrackerFrame()
{
   super("Demonstrating Mouse Events");

   mousePanel = new JPanel(); 
   mousePanel.setBackground(Color.WHITE); 
   add(mousePanel, BorderLayout.CENTER); // add panel to JFrame

   statusBar = new JLabel("Mouse outside JPanel"); 
   add(statusBar, BorderLayout.SOUTH); // add label to JFrame

   // create and register listener for mouse and mouse motion events
   MouseHandler handler = new MouseHandler(); 
   mousePanel.addMouseListener(handler); 
   mousePanel.addMouseMotionListener(handler); 
}
 
Example 2
Project: Cognizant-Intelligent-Test-Scripter   File: ImageGallery.java   View Source Code Vote up 6 votes
/**
 * set up the thumb image UI
 *
 * @param f
 * @return
 */
JPanel getPanel(final String f) {
    setThumbImage(f);
    JPanel p = new JPanel() {
        @Override
        public void paintComponent(Graphics g) {
            g.drawImage(thumbs.get(f), 0, 0, null);
        }
    };
    p.setPreferredSize(THUMB_SIZE);
    p.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
    JComponent c = getThumbSelector(f);
    JComponent cl = setupThumbClose(p);
    setupAlignment(p, c, cl);
    p.setName(f);
    p.addMouseListener(thumbselected);
    p.addMouseListener(Listeners.thumbPrevFocus);
    thumbList.add(p);
    return p;
}
 
Example 3
Project: incubator-netbeans   File: ComponentDetailsProvider.java   View Source Code Vote up 5 votes
protected void setupGlassPane(JPanel glassPane) {
    this.glassPane = glassPane;
    if (mouse != null) {
        glassPane.addMouseListener(mouse);
        if (enableInteraction) {
            glassPane.addMouseMotionListener(mouse);
        }
    }
}
 
Example 4
Project: Equella   File: JCalendar.java   View Source Code Vote up 5 votes
private JComponent createCentre()
{
	dayGrid = new JPanel(new GridLayout(7, 7, 5, 5));
	dayGrid.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
	dayGrid.setBackground(Color.WHITE);
	dayGrid.addMouseListener(this);

	Map<TextAttribute, Float> dayAttributes = new HashMap<TextAttribute, Float>();
	dayAttributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
	Font dayFont = new Font(dayAttributes);

	for( int i = 0; i < DAYS.length; i++ )
	{
		JLabel day = new JLabel(DAYS[i]);
		day.setHorizontalAlignment(SwingConstants.CENTER);
		day.setVerticalAlignment(SwingConstants.CENTER);
		day.setFont(dayFont);

		dayGrid.add(day);
	}

	days = new DayLabel[6][7];
	for( int i = 0; i < days.length; i++ )
	{
		for( int j = 0; j < days[i].length; j++ )
		{
			days[i][j] = new DayLabel();
			days[i][j].setDay(0);
			dayGrid.add(days[i][j]);
		}
	}

	return dayGrid;
}