Tabnine Logo
Component.addMouseListener
Code IndexAdd Tabnine to your IDE (free)

How to use
addMouseListener
method
in
java.awt.Component

Best Java code snippets using java.awt.Component.addMouseListener (Showing top 20 results out of 1,125)

Refine searchRefine arrow

  • Window.setVisible
  • Container.add
  • JFrame.setDefaultCloseOperation
  • JFrame.<init>
  • Window.pack
origin: stackoverflow.com

 import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JPanel {

 public MainClass() {

   addMouseListener(new MouseAdapter() { 
     public void mousePressed(MouseEvent me) { 
      System.out.println(me); 
     } 
    }); 

 }

 public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.getContentPane().add(new MainClass());

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  frame.setSize(200, 200);
  frame.setVisible(true);
 }
}
origin: stackoverflow.com

  this.setLayout(new BorderLayout());
  checkBox = new JCheckBox();
  add(checkBox, BorderLayout.CENTER);
  setOpaque(false);
this.addMouseListener(new MouseListener() {
  public void mouseClicked(MouseEvent arg0) {
    TreePath tp = selfPointer.getPathForLocation(arg0.getX(), arg0.getY());
origin: stackoverflow.com

 public class InputJFrame1 extends javax.swing.JFrame
{
  private javax.swing.JTextField numberJTextField;

  public InputJFrame1()
  {     
     initComponents(); //Init components before using textfield
     numberJTextField.addMouseListener(new MyMouseAdapter(numberJTextField));
  }

  private void initComponents() 
  {
    numberJTextField = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    getContentPane().add(numberJTextField);
  }
origin: org.htmlparser/htmlparser

/** Creates new form BeanyBaby */
public BeanyBaby ()
{
  initComponents ();
  mTrail = new Vector ();
  mCrumb = -1;
  // shenanigans to get the splitter bar at the midpoint
  setVisible (true);
  mSplitPane.setDividerLocation (0.5); // 50% for each pane
  setVisible (false);
  // set up twinning
  mLinkBean.addPropertyChangeListener (this);
  mStringBean.addPropertyChangeListener (this);
  // set up user input
  mTextField.addActionListener (this);
  mLinkBean.addMouseListener (this);
  // set initial checkbox states
  mLinks.setSelected (mStringBean.getLinks ());
  mCollapse.setSelected (mStringBean.getCollapse ());
  mNobreak.setSelected (mStringBean.getReplaceNonBreakingSpaces ());
}
origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
button.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    popup.show(e.getComponent(), e.getX(), e.getY());
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
origin: stackoverflow.com

this.addMouseListener(this);
this.addFocusListener(this);
this.addActionListener(this);
p.add(linkLabelFile);
p.add(linkLabelWeb);
labelConstrain.add( linkLabelConstrain, BorderLayout.EAST );
p.add(labelConstrain);
origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
textField.addMouseListener(new MouseAdapter(){
  @Override
  public void mouseClicked(MouseEvent e){
frame.add(textField);
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

this.addMouseListener(listener);
isLiving = random.nextBoolean();
    GameOfLife cell = new GameOfLife(ii, jj);
    cell.setPreferredSize(new Dimension(10, 10));
    gui.add(cell);
    biosphere[ii][jj] = cell;
origin: stackoverflow.com

addMouseListener(myMouseAdapter);
addMouseMotionListener(myMouseAdapter);
JFrame frame = new JFrame("DrawStuff");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DrawStuff());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
origin: stackoverflow.com

glassPane.addMouseListener(new MouseAdapter() {
});
glassPane.addMouseMotionListener(new MouseMotionAdapter() {
if (useSlideButton) {
  final JPanel statusPanel = new JPanel();
  basePanel.add(statusPanel, BorderLayout.SOUTH);
  statusPanel.add(new JButton("Slide Left") {
    private static final long serialVersionUID = 9204819004142223529L;
  statusPanel.add(new JButton("Slide Right") {
origin: stackoverflow.com

    JFrame frame = new JFrame();
    frame.setLayout(new GridLayout(N, N, N, N));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for (int i = 0; i < N * N; i++) {
      frame.add(new RotatePanel());
    frame.pack();
    frame.setVisible(true);
this.setPreferredSize(new Dimension(
  image.getWidth(null), image.getHeight(null)));
this.addMouseListener(new MouseAdapter() {
origin: stackoverflow.com

  add(checkBox, BorderLayout.WEST); 
  add(renderer, BorderLayout.CENTER);     
tree.addMouseListener(this); 
selectionModel.addTreeSelectionListener(this); 
origin: stackoverflow.com

JFrame f = new JFrame("AnimationTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
timer.start();
this.setOpaque(false);
this.setPreferredSize(new Dimension(WIDE, HIGH));
this.addMouseListener(new MouseHandler());
this.addComponentListener(new ComponentHandler());
  Dimension d = field.getPreferredSize();
  field.setBounds(e.getX(), e.getY(), d.width, d.height);
  add(field);
origin: stackoverflow.com

JFrame frame = new JFrame( "Double Click Test" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.addMouseListener( new ClickListener()
frame.setVisible(true);
origin: stackoverflow.com

jPanel2.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent evt) {
    jPanel2MousePressed(evt);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
EventQueue.invokeLater(new Runnable() {
  public void run() {
    new JavaPaintUI().setVisible(true);
origin: stackoverflow.com

  JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new TestPane());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
    add(cellPane, gbc);
addMouseListener(new MouseAdapter() {
  @Override
  public void mouseEntered(MouseEvent e) {
origin: stackoverflow.com

private JFrame frame = new JFrame();
    setLayout(new FlowLayout(FlowLayout.RIGHT));
    add(label);
    label.addMouseListener(new MouseAdapter() {
      public void mouseReleased(MouseEvent e) {
        System.exit(0);
    addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent me) {
    add(new MainPanel(), BorderLayout.CENTER);
    add(new BorderPanel(), BorderLayout.PAGE_START);
    setBorder(new LineBorder(Color.BLACK, 5));
  frame.setUndecorated(true);
  frame.add(new OutsidePanel());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
origin: stackoverflow.com

  for (int col = 0; col < GRID_COLS; col++) {
    panelGrid[row][col] = new JPanel(new GridBagLayout());
    backingPanel.add(panelGrid[row][col]);
redLabel.setBackground(Color.red.brighter().brighter());
redLabel.setPreferredSize(LABEL_SIZE);
panelGrid[4][3].add(redLabel);
panelGrid[1][1].add(blueLabel);
add(backingPanel, JLayeredPane.DEFAULT_LAYER);
MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
addMouseListener(myMouseAdapter);
addMouseMotionListener(myMouseAdapter);
JFrame frame = new JFrame("DragLabelOnLayeredPane");
frame.getContentPane().add(new DragLabelOnLayeredPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
origin: stackoverflow.com

addMouseListener(new MouseAdapter() {
 public void mouseReleased(MouseEvent e) {
JFrame test = new JFrame("Tab test");
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(400, 400);
tabs.addTab("Four", new JButton("Four"));
test.add(tabs);
test.setVisible(true);
origin: stackoverflow.com

this.addMouseListener(mouseHandler);
this.addMouseMotionListener(mouseHandler);
  this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0));
  this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA));
  this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0));
  this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA));
JFrame f = new JFrame("LinePanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.add(new ControlPanel(), BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
java.awtComponentaddMouseListener

Javadoc

Adds the specified mouse listener to receive mouse events from this component. If listener l is null, no exception is thrown and no action is performed.

Popular methods of Component

  • getParent
    Gets the parent of this component.
  • getPreferredSize
    Gets the preferred size of this component.
  • getHeight
    Returns the current height of this component. This method is preferable to writingcomponent.getBound
  • getWidth
    Returns the current width of this component. This method is preferable to writingcomponent.getBounds
  • isVisible
    Determines whether this component should be visible when its parent is visible. Components are initi
  • setBounds
    Moves and resizes this component to conform to the new bounding rectangle r. This component's new po
  • getName
    Gets the name of the component.
  • getSize
    Stores the width/height of this component into "return value" rv and return rv. If rv is null a newD
  • setEnabled
    Enables or disables this component, depending on the value of the parameter b. An enabled component
  • setBackground
    Sets the background color of this component. The background color affects each component differently
  • setVisible
    Shows or hides this component depending on the value of parameterb.
  • getMinimumSize
    Gets the mininimum size of this component.
  • setVisible,
  • getMinimumSize,
  • getBackground,
  • getBounds,
  • setForeground,
  • repaint,
  • setCursor,
  • setSize,
  • requestFocus

Popular in Java

  • Reactive rest calls using spring rest template
  • putExtra (Intent)
  • scheduleAtFixedRate (Timer)
  • onRequestPermissionsResult (Fragment)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now